Hi all:
I have two date variables in the following format: hh:mm:ss:ss. The first variable represents bedtime and the second variable represents wakeup time. I would like to create a numeric variable that represents total hours slept. So for example, the first variable has a value of 21:00:00:00 and the second variable has the value 4:00:00:00. I would like the new duration variable to reflect the value of 7. What's the best way of doing this? Thanks! Jordan ===================== 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 |
Jordan,
Suppose bedtime and wakeuptime are time10.1. True?? Sometimes bedtime and wakeuptime are different days but assumed less than 24 hours apart. Do if (bedtime lt wakeuptime). + compute sleep=wakeuptime-bedtime. Else. + compute sleep=time.hms(24,0,0)-bedtime+wakeuptime. End if. Format sleep(time8). Gene Maguin -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jordan Kennedy Sent: Tuesday, March 06, 2012 3:58 PM To: [hidden email] Subject: calculating a duration variable Hi all: I have two date variables in the following format: hh:mm:ss:ss. The first variable represents bedtime and the second variable represents wakeup time. I would like to create a numeric variable that represents total hours slept. So for example, the first variable has a value of 21:00:00:00 and the second variable has the value 4:00:00:00. I would like the new duration variable to reflect the value of 7. What's the best way of doing this? Thanks! Jordan ===================== 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 |
Administrator
|
In reply to this post by Jordan Kennedy
Look at the Date and Time Wizard in the Transform menu.
Do you also have the dates stored? They would be helpful, as the wake-up time may not always be on the subsequent day (e.g., if someone retires after midnight). If you do have both date and time variables, they can be combined into datetime variables. For example: data list list / datevar (date11) timevar(time11). begin data 5-Mar-2012 21:00:00:00 6-Mar-2012 4:00:00:00 end data. numeric dtvar (datetime). compute dtvar = datevar + timevar. list. OUTPUT: datevar timevar dtvar 05-MAR-2012 21:00:00 05-MAR-2012 21:00:00 06-MAR-2012 4:00:00 06-MAR-2012 04:00:00 With two such date-time variables (for bedtime and wake-up time), you could use the DATEDIFF function to get the difference in whatever units you want. Look it up in the fine manual. HTH.
--
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/). |
Administrator
|
In reply to this post by Jordan Kennedy
data list list/BT (Time11) WU (Time11).
begin data 12:00:00:00 21:00:00:00 21:00:00:00 4:00:00:00 07:00:00:00 12:00:00:00 end data. list. COMPUTE slept = WU-BT + (WU<BT)*86400. FORMAT slept (Time11). list. <quote author="Jordan Kennedy"> Hi all: I have two date variables in the following format: hh:mm:ss:ss. The first variable represents bedtime and the second variable represents wakeup time. I would like to create a numeric variable that represents total hours slept. So for example, the first variable has a value of 21:00:00:00 and the second variable has the value 4:00:00:00. I would like the new duration variable to reflect the value of 7. What's the best way of doing this? Thanks! Jordan ===================== 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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Free forum by Nabble | Edit this page |