BookmarkSubscribeRSS Feed
Calcite | Level 5

Hi, I am wanting to know if there is an easy way to group variables together on the x-axis. I have a column for the states, and and on each of their row I have gas prices. I would like my barchart graph to have 4 regions on the bottom, region 1,2,3,4. With the mean of gas prices for the states in those regions.


I am able to produce a graph that has 50 points on the x axis, is there a way I can say these states should be in region 1, and these states should be in region 2, and so on? 

Diamond | Level 26

A possibility


  1. Create a custom format assigning multiple states to regions
  2. PROC SUMMARY to create the mean by region
  3. PROC SGPLOT VBAR on the output from PROC SUMMARY
Paige Miller

You don't need to summarize the data. The VBAR statement will do that for you.


data Have;
length State $2;
input State Gas;
AL      2.89
FL      2.93
CA      3.55
NV      2.99
MN      3.05
MI      3.12
NY      3.24
MA      3.33

proc format;
value $Region
 'AL', 'FL' /* etc */ = 'SE'
 'NY', 'MA' /* etc */ = 'NE'
 'MN', 'MI' /* etc */ = 'MW'
 'CA', 'NV' /* etc */ = 'W';

proc sgplot data=Have;
format State $Region.;
vbar State / response=Gas stat=mean;
Barite | Level 11

If I'm understanding correctly I think I have something close to what you're looking for.  All you would need is to add another column containing the region you want each state to be in for the grouping.



proc sgpanel;
    panelby origin / rows=1 columns=3 novarname uniscale=row;
    vbar type / response=msrp stat=mean;



I used SGPANEL so that you can use your region grouping variable in the panels while keeping the TYPE variable (which would be the states in your case) on the x-axis for categorizing the bars.  There are options I believe for removing the borders and such, only option I didn't see was a way to move the grouping labels (origin in the example) to the bottom.  The Uniscale option makes each panel able to have unique column axes.







Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 4 in conversation