When I was at the Joint Statistical Meetings (JSM) last week, a SAS customer asked me whether it was possible to use the SGPLOT procedure to produce side-by-side bar charts. The answer is "yes" in SAS 9.3, thanks to the new GROUPDISPLAY= option on the VBAR and HBAR statements. For example, the following SAS code creates side-by-side bar charts that enable you to compare the relative frequencies for Asian, European, and American vehicles across several different types of vehicles:
/* SAS 9.3 supports side-by-side plots */ proc sgplot data=sashelp.cars; vbar type /group=Origin groupdisplay=cluster; run;
You can't get quite the same look from SAS 9.2, although you can panel the data to get the general appearance:
/* SAS 9.2 doesn't support side-by-side charts, but you can panel the data */ proc sgpanel data=sashelp.cars; panelby type; vbar Origin / group=Origin; run;
The GROUP= option is optional, but results in the bar being colored according to the levels of the Origin variable.
If you have SAS 9.2M3, my colleague, Sajay Matange, told me about an option that almost enables you to get side-by-side bar charts. You can use the LAYOUT= option to tell the SGPANEL procedure to use only one row for the panel. If you have only a few categories (in this case, types of vehicles), this trick works, but if you have too many categories, the procedure "helpfully" makes additional rows of plots:
/* If you have SAS 9.22 (=9.2M3) try this, which only works for about 3 groups (after that the panel makes a new row) */ proc sgpanel data=sashelp.cars; where type="SUV" | type="Sports" | type="Wagon"; panelby type / layout=columnlattice colheaderpos=bottom rows=1 novarname; vbar Origin / group=Origin; colaxis display=none; rowaxis grid; run;
Because of helpful comments like that, I'm sure to pre-order Sanjay's forthcoming book, Statistical Graphics Procedures by Example: Effective Graphs Using SAS.