BookmarkSubscribeRSS Feed
Calcite | Level 5

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

Super User

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.

Obsidian | Level 7

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 /



Hope this helps,

Jim Horne

Calcite | Level 5
thanks, but when i use the values option values=(a to b by c) is changes my data and groups it by month. So for example, instead of having 365 bars there are only 12. I want 365 bars but only 12 ticks on my x axis.
Meteorite | Level 14

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;




Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 4 in conversation