Amadeus cookies policy - you'll see this message only once.

Amadeus use cookies on this website. They help us to know a little bit about you and how you use our website, which improves the browsing experience and marketing - both for you and for others. They are stored locally on your computer or mobile device. To accept cookies, continue browsing as normal. Or, go to the privacy policy for more information.

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 =;
  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;

201101 MJ Grouped Bar Charts with SGPANEL