Compute sleep time
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | * To compute the number of hours of sleep (the date is not available from the data). * Raynald Levesque. NEW FILE. DATA LIST LIST /id(F8) Sleetime(TIME5) sampm(A2) waketime(TIME5) wampm(A2). BEGIN DATA. 1 12:00 PM 11:00 AM 2 2:00 AM 10:00 AM 3 4:00 AM 1:00 PM 4 11:30 PM 12:30 PM 5 12:30 AM 12:45 PM END DATA. LIST. * I assume sleep time of half past midnight is coded as 12:30 AM. COMPUTE timebeg=12+sleetime/3600. IF sampm='AM' AND (XDATE.HOUR(sleetime)<>12) timebeg=timebeg+12. COMPUTE timeend=24+waketime/3600. IF wampm='PM' AND (XDATE.HOUR(waketime)<>12) timeend=timeend+12. COMPUTE dur1=timeend-timebeg. * Here dur1 is a real number (10.25 means 10 hours 15 minutes) * if you want answer in HH:MM format. COMPUTE dur2=dur1*3600. FORMATS dur2(TIME5). EXECUTE. NEW FILE. DATA LIST LIST /id(F8) Sleetime(DTIME8) waketime(DTIME8). BEGIN DATA. 1 1:00:00 1:11:00 2 1:2:00 1:10:00 3 1:4:00 1:1:00 4 0:11:30 1:12:30 5 1:00:30 1:12:45 END DATA. LIST. * version 2. * Here time is entered in DTIME format, in this format. * 0 21:00 means 9 PM the day before the survey. * 1 00:30 means half past midnight. * 1 01:00 means 1 AM the day of the survey. * 1 12:30 means 12:30 PM the day of the survey. COMPUTE dur3=dwtime-dstime. FORMAT dur3 (TIME5). *Here dur3 is duration in hours and minutes (10:30 is 10 hours and 30 minutes). EXECUTE. |
Related pages
...