Creating a Grouped Bar Chart with Proc SGPANEL
The Statistical Graphics (SG) family of SAS/GRAPH procedures was introduced with SAS 9.2 and brings with it a revolution in producing high quality graphics from SAS. The SGPLOT procedure can be used to easily create stacked bar charts, however it's not so obvious how to create a grouped bar chart with the bars placed alongside each other rather than stacked.
The solution to this problem lies in the SGPANEL procedure which is generally used to create panelled plots where each panel contains the same graph for a different value of a classification variable. The careful use of options on the SGPANEL statements allows us to create effective grouped bar charts.
The following code (which requires SAS 9.2 Phase 2 onwards) will produce the bar chart shown below:
title1 "Average MPG (City) by Vehicle Origin and Type"; proc sgpanel data = sashelp.cars; panelby origin / layout=columnlattice onepanel novarname noborder colheaderpos=bottom; vbar type / response=mpg_city group=type stat=mean; colaxis display=none; rowaxis label="Average MPG (City)"; keylegend / title="Type" position=right across=1; run;