04-21-2017 07:14 AM
I have bed times for a sample of 6000 chidren in hrs:minutes:secs (e.g. 21:35:03), and I would like to calculate mean(s) and also use the bed time as a dependent variable in Multilevel model. My question is can someone help me with the sas code for the means especially when some of the bed times are past midnight, and others are before? Lastly how can I use this variable as a dependent var?
Thank you kindly.
04-21-2017 07:22 AM
Thank you for your quick response.
For example, I have these bed times: 22:46:20; 0:57:15; 0:36:00;23:02:20;21:22:00;20:10:15;19:45:12;3:04:00. These are individual bed times, can I want compute proc means?
04-21-2017 08:41 AM
Post test data in the form of a datastep.
This seems to be a learning excercise, consult your learning materials and the manual:
04-21-2017 08:47 AM
ok. So your data looks like this right?
data have; format bed_time time.; input bed_time :time.; datalines; 22:46:20 00:57:15 00:36:00 23:02:20 21:22:00 20:10:15 19:45:12 03:04:00 ;
But how do you know if a childs bed time is recorded before/after midnight? Do you have some indicator of that?
04-24-2017 09:49 AM
I propose that you set a "cutoff time" that is used to determine if the bed time is before or after midnight. If the bedtime is after midnight, you need to add 24 hours (=60*60*24 seconds) so that the "bed time function" is continuous. For example, the following program uses Draycut's data step and adds 24 hours to any times that are before noon:
data want; set have; noon = 60*60*12; /* cutoff value */ t = ifn(bed_time <= noon, bed_time+2*noon, bed_time); /* add 24 hours if time before noon */ drop noon; run;
04-24-2017 05:04 PM
I would suggest recording both the date and the time in a datetime variable might be the way to proceed with future observations.