Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

time strings in SPSS for Windows

371 views
Skip to first unread message

Danny

unread,
Oct 28, 1998, 3:00:00 AM10/28/98
to
Hello.
I'm pretty rusty with SPSS and was hoping someone could help me. I've
being trying to convert an already existing ACCESS database into SPSS.
Everything has worked well except that several time variables have
been set up as follows:
'hr:mm:ss' ending with 'AM' and 'PM'. Because of the latter, I've had
to make this a string variable (there is no equivalency in SPSS data
types that I can find). I'd like to convert these variables into a 24
hour clock type or anything else that is compatible with date types in
SPSS (especially since I need to do calculations between several of
these variables). I've tried several things including trying to break
down the string into parts but none has worked. I'd really appreciate
hearing from anyone who has some ideas. Thanks a lot. Cathy
Livingstone.

Edward Tverdek

unread,
Oct 28, 1998, 3:00:00 AM10/28/98
to Danny
Cathy,

It would have helped to include a few examples of the data values you
have, or at least indicated exactly how the values "end with" the AM
and PM designations. Assuming that you mean the hh:mm:ss values
literally have "AM" or "PM" attached as a suffix, as in

09:15:33AM
11:34:12PM

you should be able to extract the relevant content and store it in a
new variable in SPSS's TIMEw format with something like this:


COMPUTE newtime=NUM(SUBSTR(oldtime,1,8),TIME8).
IF (SUBST(oldtime,9,2)='PM') newtime=newtime+TIME.DAYS(.5).
FORMATS newtime (time8).
LIST.

The first line pulls out the TIMEw content; the second adds
12 hours (i.e. .5 days) conditionally to those cases with a "PM"
designation, to adjust them for a 24-hour clock; the third
line formats the values to the hh:mm:ss display format.

You can adjust the "9" value among the SUBSTR arguments on the
conditional statement (second line) accordingly if there is a space
(or spaces) between the hh:mm:ss value and the "AM/PM" designation.

See your SPSS Syntax Reference Guide for details on the
capitalized commands and functions.

I hope these suggestions are useful,

Ed Tverdek

0 new messages