04-06-2015 09:53 AM
Hey everyone, I'm pretty new to SAS, and am having trouble calculating the mean time for a dataset.
My data is in military time, but the problem is that the central peak of the distribution is centered at midnight. So, instead of having a single peak at midnight, SAS gives me two peaks: one around 11:59 PM and another around 12:01 AM (or, as my dataset has, one peak at 2359 and another 0001).
I was wondering how I might code SAS to realize that time is continuous through midnight.
By the way, my code so far looks like this:
proc univariate data=timesr;
Thank you in advance!
04-06-2015 11:53 AM
Basically SAS is using a continuous time either in seconds (floating number) or in days (floating number) wit a point of zero at 1 jan 1960 (make that Zulu time going into NLS). SAS(R) 9.4 Language Reference: Concepts, Fourth Edition Whatever you have done with the var hour is something that disturbed that concepts.
Another basic one with SAS is that you do not need to recode content/real values but can apply formatting. SAS(R) 9.4 Formats and Informats: Reference
SAS(R) 9.4 Formats and Informats: Reference Limiting the length to hour or defining a own format handling that should solve your question.
There is not that information on the data you are processing, please give more info.....
04-06-2015 11:54 AM
Does your data have a date component?
If so, add a date to your time variable and then format it to show only the time.
Another method would be to centre the data around midnight and then draw the histogram.
04-10-2015 12:50 PM
I'd hate to do this, but every time I try this format, my datatable is simply replaced with 1 observation that reads ".".
I've converted all my times to the standard SAS serial code for time (i.e. seconds after midnight), but to no avail.
04-11-2015 06:20 PM
Are you sure you have proper SAS datetime value in the variable?
What happens if you put the datetime20. format on it? Does it work?
What is your plan about determining the "mean time"? (Which I think is rather the peak hour?)
Some SAS procedures will honor the format you apply (typically, when you treat time/datetime as a category variable), and some procedures won't use the format (those that treat time/datetime as continuous).
You can also create bins without using formats.
First of all, you can divide time by 60 or 3600 etc. and round the results. Or you can round to the nearest hour with the round function. Or you can use the intnx() function.
04-06-2015 04:17 PM
If you want to illustrate on a chart, that time is continuous through midnight then this is a (rare) case when a radar chart is adequate:
do i=1 to 10000;
format t tod2.;
proc gradar data=time;
If you want to identify "peak hours", "peak minutes" or something similar, then you are looking for the mode of the distribution with a "cyclical twist".
proc univariate data=time2 round=60 modes;
var timePartOrig timePartReCent;
You can see in this example, that I am using rounding (otherwise the is no mode of the data, because in my generated data time is continuous, and no value occurs twice.). If your data is similar, other procedures might be more useful to extract "peaks". (eg: prockde)