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);
run;
I tried this option, but no luck:
values=(1 to 365 by month) * date data is in julday3. format
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.
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;
XAXIS DISPLAY=NONE;
Hope this helps,
Jim Horne
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: