Calcite | Level 5

## how to do do some means and other calculations for daily data

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
Super User

## Re: how to do do some means and other calculations for daily data

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

Calcite | Level 5

## Re: how to do do some means and other calculations for daily data

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?

Diamond | Level 26

## Re: how to do do some means and other calculations for daily data

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...

Super User

## Re: how to do do some means and other calculations for daily data

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?

SAS Super FREQ

## Re: how to do do some means and other calculations for daily data

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;
``````
Calcite | Level 5

## Re: how to do do some means and other calculations for daily data

Thank you very much for this suggestion. I will run it and will give you feedback if it works well.
Cheers
Barite | Level 11

## Re: how to do do some means and other calculations for daily data

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

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