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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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