Extracting Time

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Extracting Time

Keval Khichadia
Hi,

I have a variable Start_Time that includes the date and time of the starting time of a class. All values are in the format
(10-OCT-2008 13:50:00). I would like to create a new variable that keeps only the time part and also format the time so that 13:50 would be 1:50.

Thanks in advance,

Keval

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Extracting Time

Marks, Jim
If your variable is an SPSS datetime format:

COMPUTE timepart = xdate.time(start_time).
FORMAT timepart (time6).

This will give you the time formatted as hh:mm.

I don't think 1:30 is a valid format for 1:30 pm in SPSS-- you could
create a string to look like that, but I'm not sure if that would help.

Jim Marks
Director of Market Research
x 1616


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Keval Khichadia
Sent: Thursday, December 04, 2008 1:01 PM
To: [hidden email]
Subject: Extracting Time

Hi,

I have a variable Start_Time that includes the date and time of the
starting time of a class. All values are in the format
(10-OCT-2008 13:50:00). I would like to create a new variable that keeps
only the time part and also format the time so that 13:50 would be 1:50.

Thanks in advance,

Keval

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

SPSS vs. Stata for Complex Samples

Nora Jones
Greetings,

Back in August, I saw a brief discussion about SPSS and weighting for complex samples.  Our organization is now in the position of needing to compute significance estimates/confidence intervals for a complex sample.  We are most familiar with SPSS at this point, but do not currently have the SPSS Complex Samples component.  Another organization that we are collaborating with is recommending we purchase Stata and begin to use it for this project.  Has anyone here used both Stata and SPSS Complex Samples?  Anyone know of comparisons that may have been done between the two?  If so, how do their numbers compare?  Is there anything fundamentally different in how the two handle weighting, significance, etc. in complex samples?

Thanks for any help.

-----------------------------------------------------
Nora Jones - Research Associate, Lighthouse Institute
-----------------------------------------------------
Chestnut Health Systems  | Email: [hidden email]
448 Wylie Dr.            | Phone: 309-451-7820
Normal, IL 61701         | Fax:   309-451-7764
-----------------------------------------------------

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Extracting Time

Richard Ristow
In reply to this post by Keval Khichadia
At 02:00 PM 12/4/2008, Keval Khichadia wrote:

>I have a variable Start_Time that includes the date and time of the
>starting time of a class. I would like to create a new variable that
>keeps only the time part ...

As Jim Marks wrote, XDATE.TIME does this.

>and also format the time so that 13:50 would be 1:50.

There is, unfortunately, no SPSS time format to either read or
display times in am/pm form. (I think it's a deficiency.) You can do
something like this (tested code) to calculate the am/pm form:

NUMERIC time12(TIME6).
STRING  am.pm (A2).

DO IF   MISSING(timepart).
.  COMPUTE time12 = $SYSMIS.
.  COMPUTE am.pm  = ''.
ELSE IF timepart LT TIME.HMS(01)  /* Midnight <= 1:00 am  */.
.  COMPUTE time12 = timepart + TIME.HMS(12).
.  COMPUTE am.pm  = 'am'.
ELSE IF timepart LT TIME.HMS(12) /*  1:00 am  <= noon     */.
.  COMPUTE time12 = timepart.
.  COMPUTE am.pm  = 'am'.
ELSE IF timepart LT TIME.HMS(13) /*  noon     <= 1:00 pm  */.
.  COMPUTE time12 = timepart.
.  COMPUTE am.pm  = 'pm'.
ELSE                            /*   1:00 pm  <= midnight */.
.  COMPUTE time12 = timepart - TIME.HMS(12).
.  COMPUTE am.pm  = 'pm'.
END IF.

LIST.

List
|-----------------------------|---------------------------|
|Output Created               |06-DEC-2008 02:45:29       |
|-----------------------------|---------------------------|
timepart time12 am.pm

    0:45   12:45 am
    1:23    1:23 am
   10:14   10:14 am
   12:30   12:30 pm
   13:45    1:45 pm
   17:20    5:20 pm
   23:10   11:10 pm

Number of cases read:  7    Number of cases listed:  7
============================
APPENDIX: Test data and code
(WRR: not saved separately)
============================
DATA LIST FREE /timepart (TIME6).
BEGIN DATA
00:45 1:23 10:14 12:30 13:45 17:20 23:10
END DATA.
.  /**/ LIST /*-*/.

NUMERIC time12(TIME6).
STRING  am.pm (A2).

DO IF   MISSING(timepart).
.  COMPUTE time12 = $SYSMIS.
.  COMPUTE am.pm  = ''.
ELSE IF timepart LT TIME.HMS(01)  /* Midnight <= 1:00 am  */.
.  COMPUTE time12 = timepart + TIME.HMS(12).
.  COMPUTE am.pm  = 'am'.
ELSE IF timepart LT TIME.HMS(12) /*  1:00 am  <= noon     */.
.  COMPUTE time12 = timepart.
.  COMPUTE am.pm  = 'am'.
ELSE IF timepart LT TIME.HMS(13) /*  noon     <= 1:00 pm  */.
.  COMPUTE time12 = timepart.
.  COMPUTE am.pm  = 'pm'.
ELSE                            /*   1:00 pm  <= midnight */.
.  COMPUTE time12 = timepart - TIME.HMS(12).
.  COMPUTE am.pm  = 'pm'.
END IF.

LIST.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Extracting Time

Peck, Jon
-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Richard Ristow
Sent: Saturday, December 06, 2008 12:48 AM
To: [hidden email]
Subject: Re: [SPSSX-L] Extracting Time

At 02:00 PM 12/4/2008, Keval Khichadia wrote:

>I have a variable Start_Time that includes the date and time of the
>starting time of a class. I would like to create a new variable that
>keeps only the time part ...

As Jim Marks wrote, XDATE.TIME does this.

>and also format the time so that 13:50 would be 1:50.

There is, unfortunately, no SPSS time format to either read or
display times in am/pm form. (I think it's a deficiency.) You can do
something like this (tested code) to calculate the am/pm form:

[>>>Peck, Jon] Or use the date/time pattern language available in the Python module extendedTransforms available from Developer Central.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Extracting Time

Orange County Stats Tutor
In reply to this post by Keval Khichadia
Hi, Keval.

You could try the replace feature in the Edit drag down menu.

For example, when I imported from ACCESS to SPSS, SPSS left the times '00:00:00'. I only wanted to see the dates without the times. I took care of this by replacing '00:00:00' with nothing.

In replace button, write what you do not need, and in the 'replace with' field leave it blank.

Maybe this can make your life easier. Let the group know if you came to a solution.

Francesca Barocio, M.S. http://www.oc-tutor.com
Keval Khichadia wrote
Hi, I have a variable Start_Time that includes the date and time of the starting time of a class. All values are in the format (10-OCT-2008 13:50:00). I would like to create a new variable that keeps only the time part and also format the time so that 13:50 would be 1:50. Thanks in advance, Keval ===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Extracting Time

Hal 9000
In reply to this post by Keval Khichadia
> I have a variable Start_Time that includes the date and time of the starting time of a class. All values are in the format
> (10-OCT-2008 13:50:00). I would like to create a new variable that keeps only the time part and also format the time so that 13:50 would be 1:50.

new file.
data list free /Text_DateTime (a20).
begin data
"10-OCT-2008 13:50:00"
end data.
dataset name TST window = front.
compute Time_12HR =
time.hms(mod(number(substr(Text_DateTime,index(Text_DateTime,"
")+1),f2.0),12),number(substr(substr(Text_DateTime,index(Text_DateTime,"
")+1),index(substr(Text_DateTime,index(Text_DateTime,"
")+1),":")+1,2),f2.0),00).

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD