- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks!