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!
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;
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.
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.
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;
Thanks!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.