BookmarkSubscribeRSS Feed
tmanyanga
Calcite | Level 5

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

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

Use Proc Means, but first, post some sample data, that makes is much easier to help.

tmanyanga
Calcite | Level 5

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?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep.

This seems to be a learning excercise, consult your learning materials and the manual:

http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#n0k7qr5c2ah3stn10g1lr...

 

PeterClemmensen
Tourmaline | Level 20

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?

 

Rick_SAS
SAS Super FREQ

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;
tmanyanga
Calcite | Level 5
Thank you very much for this suggestion. I will run it and will give you feedback if it works well.
Cheers
HB
Barite | Level 11 HB
Barite | Level 11

I would suggest recording both the date and the time in a datetime variable might be the way to proceed with future observations.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1308 views
  • 0 likes
  • 5 in conversation