Here is my data:
group-var | datetime |
a | 09AUG2014:07:52:00 |
b | 17JUL2014:19:32:00 |
b | 30JUL2014:16:15:00 |
c | 12JUL2014:07:02:00 |
a | 12JUL2014:09:41:00 |
c | 15JUL2014:21:23:00 |
b | 14AUG2014:20:52:00 |
c | 15SEP2014:11:32:00 |
a | 22SEP2014:09:14:00 |
b | 01JUL2014:12:27:00 |
c | 03JUL2014:09:33:00 |
a | 03JUL2014:09:04:00 |
b | 12JUL2014:17:58:00 |
b | 28JUL2014:14:37:00 |
b | 04JUL2014:14:56:00 |
b | 26JUL2014:21:32:00 |
c | 30OCT2014:18:42:00 |
c | 06JAN2015:14:47:00 |
c | 30SEP2014: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!
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;
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.