Data visualization with SAS programming

Simple way to do histogram by dates

Reply
Occasional Contributor
Posts: 10

Simple way to do histogram by dates

Here is my data:

 

group-vardatetime
a09AUG2014:07:52:00
b17JUL2014:19:32:00
b30JUL2014:16:15:00
c12JUL2014:07:02:00
a12JUL2014:09:41:00
c15JUL2014:21:23:00
b14AUG2014:20:52:00
c15SEP2014:11:32:00
a22SEP2014:09:14:00
b01JUL2014:12:27:00
c03JUL2014:09:33:00
a03JUL2014:09:04:00
b12JUL2014:17:58:00
b28JUL2014:14:37:00
b04JUL2014:14:56:00
b26JUL2014:21:32:00
c30OCT2014:18:42:00
c06JAN2015:14:47:00
c30SEP2014:19:18:00

Is there a way to do either of the following:

 

1) a simple set of histograms, one for each grouped_var, that adds up the number of observations for that group each month? (I would rather not type out each group_var, as there are more than just a,b, and c.)

 

2) a multiple series line chart that has a separate series for each grouped_var that shows the number of occurences of for each month?

 

I searched but couldn't find the answer, so thank you so much in advance!

SAS Super FREQ
Posts: 3,221

Re: Simple way to do histogram by dates

[ Edited ]

What you are looking for is called a "comparative histogram," and searching on that term will lead you to many articles, including this summary article "Comparative histograms: Panel and overlay histograms in SAS."  From your description, it sounds like you want to use the panel approach:

 

 

proc sgpanel data=sashelp.iris;
  panelby group-var;
  histogram datetime;
run;

You might want to add a COLAXIS statement and specify the INTERVAL= option to get axis ticks that are convenient for your data.

 

I'm not sure what you mean by a "multiple time series chart" for this data. Look at the VLINE statement and the STAT=SUM option. However, I think you would need to bin the data to the month level, probably by using a format.  Thus try starting with the following:

 


proc sgpanel data=A;
format datetime DTMONYY5.;
panelby groupvar;
vbar datetime / stat=sum;   /* I prefer VBAR */
vline datetime / stat=sum markers break;
run;

 

Grand Advisor
Posts: 9,682

Re: Simple way to do histogram by dates

Pet peeve: DATES and DATETIMES are different, especially in SAS. So do you want dates or datetimes for your histogram?

 

What would be the Y variable for a series chart? You show a group variable and an x axis variable but a series is going to want something to show as a Y.

Occasional Contributor
Posts: 10

Re: Simple way to do histogram by dates

I think I would need to extract the datepart(). I was hoping the series chart could just do a frequency rather than another variable for Y.
Post a Question
Discussion Stats
  • 3 replies
  • 143 views
  • 0 likes
  • 3 in conversation