Recoding Date/Time/HH:MM into Groups

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

Recoding Date/Time/HH:MM into Groups

ManyPaths
I'm working with a dataset that asked people to report their usual bedtime (Q5_SleepTime). It's archived in SPSS as a numerical variable, variable type is date/time variable (HH:MM).

I'm trying to recode it so I can have the 'bed times' grouped into 1 hour increments (00:00-00:59; 01:00-01:59; 02:00-02:59, etc.). I tried the first thing that came to mind, Transform>Recode into variable, but I realized the values are saved as ##:## and the Recode function doesn't allow for colons.

I'd appreciate some help, as I'm kind of a n00b to recoding numerical/continuous variables.

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Recoding Date/Time/HH:MM into Groups

Bruce Weaver
Administrator
Have you looked at the XDATE.HOUR function?  From the Command Syntax Reference manual (aka, the FM):

XDATE.HOUR(datetime). Numeric. Returns the hour (an integer between 0 and 23) from a value that represents a time or a datetime. The argument can be a number, a time or datetime variable or an expression that resolves to a time or datetime value.

Example, assuming BedTime is a DATE-TIME formatted variable:

COMPUTE BedTimeHour = XDATE.HOUR(BedTime).
FORMATS BedTimeHour(F2.0).


ManyPaths wrote
I'm working with a dataset that asked people to report their usual bedtime (Q5_SleepTime). It's archived in SPSS as a numerical variable, variable type is date/time variable (HH:MM).

I'm trying to recode it so I can have the 'bed times' grouped into 1 hour increments (00:00-00:59; 01:00-01:59; 02:00-02:59, etc.). I tried the first thing that came to mind, Transform>Recode into variable, but I realized the values are saved as ##:## and the Recode function doesn't allow for colons.

I'd appreciate some help, as I'm kind of a n00b to recoding numerical/continuous variables.

Thanks!
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).