Data visualization with SAS programming

PROC SGPLOT: Set x axis interval to months while keeping vbar data by day.

Reply
New Contributor
Posts: 3

PROC SGPLOT: Set x axis interval to months while keeping vbar data by day.

[ Edited ]

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

Grand Advisor
Posts: 9,740

Re: PROC SGPLOT: Set x axis interval to months while keeping vbar data by day.

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.

Occasional Contributor
Posts: 13

Re: PROC SGPLOT: Set x axis interval to months while keeping vbar data by day.

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

New Contributor
Posts: 3

Re: PROC SGPLOT: Set x axis interval to months while keeping vbar data by day.

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.
SAS Super FREQ
Posts: 1,044

Re: PROC SGPLOT: Set x axis interval to months while keeping vbar data by day.

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;

 

Post a Question
Discussion Stats
  • 4 replies
  • 1341 views
  • 0 likes
  • 4 in conversation