BookmarkSubscribeRSS Feed
mh3477
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);
run;

 

I tried this option, but no luck:

           values=(1 to 365 by month)         * date data is in julday3. format

4 REPLIES 4
ballardw
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.

jimhorne
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 /

NOLABEL POSITION=BOTTOM FILLTYPE=ALTERNATE;

XAXIS DISPLAY=NONE;

Hope this helps,

Jim Horne

mh3477
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.
Jay54
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;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 8624 views
  • 0 likes
  • 4 in conversation