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.
Taru
Use Proc Means, but first, post some sample data, that makes is much easier to help.
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?
Post test data in the form of a datastep.
This seems to be a learning excercise, consult your learning materials and the manual:
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?
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;
I would suggest recording both the date and the time in a datetime variable might be the way to proceed with future observations.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.