BookmarkSubscribeRSS Feed
appleorange
Obsidian | Level 7

I need to create a stacked bar chart/data table combo similar to this example: http://support.sas.com/kb/35/774.html.

 

 

example.jpg

 

I tried to follow it but since the actual data set has many months to display (20+) and that it might be because of months as the type of data, I get this error: 

 

WARNING: The intervals on the axis labeled "month" are not evenly spaced.
ERROR: The bottom horizontal axis labeled "month" could not be fit. There was not enough room in
the graph's display area to fit the group axis.

 

On top of that, since the example had only two groups, and mine has many, I wasn't sure how to edit the code to draw the table/fill in the lines.

 

I tried a different method and can get something kind of close, but am wondering if there was a way to use proc gchart, and to add goal lines/text labels.

 

proc transpose data=testg
out=long1(rename=(col1=value)) name=Type;
by month;
var Total visit1-visit8;
run;

proc sgplot data=long1;
xaxistable value /x=value class=type colorgroup=type;
vbar month / response=value group=type stat=sum;
run;

SGPlot2.png

1 REPLY 1
ballardw
Super User

I can guarantee that GCHART will be much harder to work with.

 

The fit of your axis labels could be addressed by use of a different format for if the Month variable is an actual date value which seems likely. The note about uneven spaces is because months are not the same length so you can pretty much ignore that. The SAS YYMON6. format will display values as a 2-digit year followed by month abbreviation. If you want to force the appearance of a - then a custom format.

proc format library=work;
picture yy_MON  (default=7)
low - high = '%y-%b' (datatype=date)
;
run;

data example;
   x= '15Jan2018'd;
   put x yy_mon.;
run;

Xaxis option splitchar of fitpolicy with split while using the above custom format to split text on the - may help a bit.

 

If your users know each bar should represent a month then THIN option reducing the text for some ticks may be appropriate.

 

Reducing the size of the font for the axis may help as well as increasing the size of the display area for the graph.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 2305 views
  • 0 likes
  • 2 in conversation