I want to compute the sleep duration of my participants. As items I have the bed time and the time they got out of bed (some went to bed before 00:00 and some after). Format is hhmmss.
To compute the sleeping Time I already found this code:
DATA LIST FREE / outofbed bedtime (2TIME5).
BEGIN DATA
08:00 22:00
06:00 21:00
05:30 20:30
21:45 07:00
END DATA.
DO IF outofbed < bedtime.
COMPUTE sleepDur = 24 – CTIME.HOURS(bedtime-outofbed).
ELSE.
COMPUTE sleepDur = CTIME.HOURS(outofbed-bedtime).
END IF.
EXECUTE.
Problem is: Some went to bed at p.e. 00:45:00 and woke up at 09:30:00. The sleep time I got is 8:75 (instead of 8:45). What can I do differently to get the right answers?
(sorry, English is not my first language)
Rosa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.