Data visualization with SAS programming

Ascending option in proc sgplot

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 102
Accepted Solution

Ascending option in proc sgplot

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
Solution
‎04-22-2013 04:32 PM
SAS Super FREQ
Posts: 1,044

Re: Ascending option in proc sgplot

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


All Replies
SAS Super FREQ
Posts: 1,044

Re: Ascending option in proc sgplot

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.

Frequent Contributor
Posts: 102

Re: Ascending option in proc sgplot

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.

Solution
‎04-22-2013 04:32 PM
SAS Super FREQ
Posts: 1,044

Re: Ascending option in proc sgplot

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;

Frequent Contributor
Posts: 102

Re: Ascending option in proc sgplot

Thanks!

Post a Question
Discussion Stats
  • 4 replies
  • 5133 views
  • 1 like
  • 2 in conversation