I have a column datetime in sas dataset and want to create a graphs to show maximum number of times exists in a range .
For eg few events occur between 2pm and 4 pm so my graph should show maximum dots or peak line during that interval.
max range for the graph should be 24 hours and each interval should be 1 hour apart.
Also from the datetime column I just need to take time portion.
regards
kajal
data have;
call streaminit(123);
do datetime=dhms('01jan2022'd,21,0,0) to dhms('02jan2022'd,3,0,0) by 60*60;
hour=scan(put(timepart(datetime),timeampm.),1,':');
count=rand('integer',100,600);
output;
end;
format datetime e8601dt.;
run;
proc sgplot data=have;
series x=hour y=count;
xaxis type=discrete discreteorder=data label='Time';
run;
A bunch of questions enter my mind:
You say: "want to create a graphs to show maximum number of times exists in a range". Maximum of what? If you take the word "maximum" out of your statement, then it makes sense to me what (I think) you want, you want the number of times this variable exists in the range. But I'm guessing.
You say "For eg few events occur between 2pm and 4 pm so my graph should show maximum dots or peak line during that interval." If there are few events, should that not be the minimum dots or lowest value on the line?
Are these always 2 hour intervals? Are we talking about multiple days, or just talking about time interval regardless of day?
sorry correction to my question.
need to create a graph showing max frequencies of 'time of event ' in a particular time range
most of the events occur between 2pm and 4 pm should show maximum dots on the graph between 2pm and 4 pm range.
Regards
kajal
I'm still not understanding your usage of "maximum" in your problem statement. Please explain in more detail.
Please show us a simple example, show us some example data and the plot you want.
In a data step the TIMEPART function will extract the time of day from a DATETIME value. Example;
data want; set have; timeofday = timepart(datetimevariable); run;
By "each interval should be 1 hour " do you mean the tick marks on the time axis or the actual values of the time rounded to 1 hour to graph, or both?
What is going on the Y axis? A count of something? A measurement or recorded value?
Thanks for the plot. So we are not calculating a maximum of anything, we are calculating a count. Is that correct?
Try this:
/* UNTESTED CODE AS I DON"T HAVE EXAMPLE DATA */
data have2;
set have;
hour=hour(yourdatetimevariable);
run;
proc freq data=have2;
table hour/noprint out=_counts_;
run;
proc sgplot data=_counts_;
series x=hour y=count;
run;
Thank you so much it also works
data have;
call streaminit(123);
do datetime=dhms('01jan2022'd,21,0,0) to dhms('02jan2022'd,3,0,0) by 60*60;
hour=scan(put(timepart(datetime),timeampm.),1,':');
count=rand('integer',100,600);
output;
end;
format datetime e8601dt.;
run;
proc sgplot data=have;
series x=hour y=count;
xaxis type=discrete discreteorder=data label='Time';
run;
Thank you so much it works
If you want this smooth plot, you need points between the hours. Do you have that detail? How many points?
Mind that the more points, the less volume by point. So if the volume is say 600 in an hour, a per-minute plot will show around 10 on the Y axis.
A per-30-minute plot will show around 300 on the Y axis. Etc.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.