Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sarahsasuser
Quartz | Level 8

I'd like to show my data (percentages of building performance 0-100%) in a vertical bar chart. The x-axis is the building ID number and so proc sgplot is ordering the x-axis by the ID number, but I'd like to order the bars in ascending order. Is there an ascending option in proc sgplot?

Also, I have a large chart and I'd like to split into two charts. Is there a way to do this so that exactly half of the data fits onto one chart and the other half onto another chart? Or will I need to tell SAS the Building ID numbers I want on chart 1 and those I want on chart 2?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

See example below.  Assuming you create a variable equivalent to the "Sex" variable, the code below will create two output graphs.  Use OPTIONS NOBYLINE to suppress the by line.

proc sort data=sashelp.class out=class;
  by sex descending height;
  run;

options nobyline;

proc sgplot data=class;
  by sex;
  vbar name / response=height;
  xaxis discreteorder=data;
  run;

View solution in original post

4 REPLIES 4
Jay54
Meteorite | Level 14

With SAS 9.3, you can use the option CATEGORYORDER=RESPDESC on the VBAR.

Or, you can sort the data in the order you need, and then use XAXIS DISCRETEORDER=DATA.

For splitting your graph, one idea is to add another column, say GROUP with two values, say 1 & 2.  Then use a BY option on the SGPLOT with this variable.

Or, use SGPANEL and use GROUP as the class variable on the PANELBY statement, and set COLUMNS and ROWS to 1.

sarahsasuser
Quartz | Level 8

Thanks Sanjay. This worked: XAXIS DISCRETEORDER=DATA.

For splitting the graph, I used your suggestion of using a by statement. Proc sgplot split the chart as desired, but included the building ids with missing data depending on the group. So the second half of the first chart is a list of the group 2 buildings with no data. Also, I would want to suppress the group=1 notation in the title as this has no meaning to user.

Jay54
Meteorite | Level 14

See example below.  Assuming you create a variable equivalent to the "Sex" variable, the code below will create two output graphs.  Use OPTIONS NOBYLINE to suppress the by line.

proc sort data=sashelp.class out=class;
  by sex descending height;
  run;

options nobyline;

proc sgplot data=class;
  by sex;
  vbar name / response=height;
  xaxis discreteorder=data;
  run;

sarahsasuser
Quartz | Level 8

Thanks!

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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
  • 4 replies
  • 19636 views
  • 1 like
  • 2 in conversation