09-28-2015 10:00 AM - edited 09-28-2015 10:01 AM
I am graphing number of cases by day over a year period. I want to keep my bar graph by day but group the axis labels by month. I've tried but each time it groups my data by month also. Any suggestions?
My graph code:
proc sgplot data=byyear;
vbar date/ response=count_2014 legendlabel="2014" fillattrs= (color=green);
xaxis label= "Date" valueattrs= (size=16pt)labelattrs=(size=20pt) interval=month;
yaxis label="Number of Cases" values=(0 to 15 by 1) valueattrs= (size=16pt)labelattrs=(size=20pt);
I tried this option, but no luck:
values=(1 to 365 by month) * date data is in julday3. format
09-28-2015 10:19 AM
You don't mention the range of dates you need but adding to the xaxis statement
values=("01JAN2014"d to "01DEC2014" by month)
would put labels at the start of each month.
The date litterals are in the that form, you can't use 01/01/2014 or similar and the variable for the xaxis has to be a SAS date value.
09-28-2015 10:46 AM
You may want to try adding variable MONTH to your data with a format something like MONYY5. Once you do that you can drop the X axis and use a BOX plot. It might look something like
FORMAT month MONYY5. ;
BLOCK X=month BLOCK=month /
NOLABEL POSITION=BOTTOM FILLTYPE=ALTERNATE;
Hope this helps,
09-28-2015 01:58 PM
09-29-2015 01:12 AM
If you really really need SGPLOT to summarize the data by day, you need to use VBAR. Then the x- axis will be discrete, and the axis will try to show each value, thinned by collisions. To avoid this you will need a format to make the non- labeled values to blank. Setting the VALUES option will subset axis range.
If you can summarize the data by day prior to SGPLOT, using MEANS, you can use a needle plot with a real time axis. Then, you can set the values as mentioned above. You could also use a HIGHLOW plot to get a bar like feel.
With SAS 9.40M3, you have best of both worlds, and you can use VBAR with a linear axis by setting XAXIS TYPE=Linear;