Data visualization with SAS programming

proc sgplot to draw bar plots, with user defined order of categories?

Accepted Solution Solved
Reply
Super Contributor
Posts: 310
Accepted Solution

proc sgplot to draw bar plots, with user defined order of categories?

I want to order the bars in the bar chart, based on my own order, not by the default order. Is there a way to do it?

 

Thanks


Accepted Solutions
Solution
‎04-26-2016 03:07 PM
SAS Super FREQ
Posts: 620

Re: proc sgplot to draw bar plots, with user defined order of categories?

Hi have a look at the VALUES= option of the XAXIS statement.

 

Find below a code sample:

proc sgplot data=sashelp.cars tmplout="c:/temp/sgplot.sas";
  vbar type / response=Horsepower stat=mean;
  xaxis values=("SUV" "Hybrid" "Wagon" "Truck");
run;

Bruno

View solution in original post


All Replies
SAS Super FREQ
Posts: 3,234

Re: proc sgplot to draw bar plots, with user defined order of categories?

Yes. Sort the data set so that the categories appear i nthe order you want. Then use the XAXIS DISCRETEORDER=DATA option to tell the plot to use the order of the categories as they appear in the data set:

 

proc sgplot data=sashelp.cars;

vbar Type;

xaxis discreteorder=data;

run;

 

 

For more elaborate examples, see the article "Order variables by values of a statistic"

Solution
‎04-26-2016 03:07 PM
SAS Super FREQ
Posts: 620

Re: proc sgplot to draw bar plots, with user defined order of categories?

Hi have a look at the VALUES= option of the XAXIS statement.

 

Find below a code sample:

proc sgplot data=sashelp.cars tmplout="c:/temp/sgplot.sas";
  vbar type / response=Horsepower stat=mean;
  xaxis values=("SUV" "Hybrid" "Wagon" "Truck");
run;

Bruno

Super Contributor
Posts: 310

Re: proc sgplot to draw bar plots, with user defined order of categories?

So great!!! Thank you!
Post a Question
Discussion Stats
  • 3 replies
  • 294 views
  • 2 likes
  • 3 in conversation