DATA Step, Macro, Functions and more

proc SGplot. X axis out of order.

Reply
Contributor
Posts: 43

proc SGplot. X axis out of order.

I'm generating a simple vbar chart with the Y axis being counts, and x axis being ranges that I created as text (i.e "0 to 5%", "5.01 to 10%" etc).

 

When I plot the chart,  my X axis is out of order.  it'll go "0 to 5%", "10 to 15%", "5 to 10%".  How do I set the order in this scenario where the x axis is text?



Proc sgplot data=gridwork.data;
vbar dist/ response=counts;
xaxis label=distribution;
yaxis label='counts;

run;
quit;
Super User
Posts: 23,773

Re: proc SGplot. X axis out of order.

Easiest method is to not use characters as your X axis. Instead use numeric values and then use a format to have them displayed for presentation. 

 

Because its a categorical variable you can also use the VALUES = option on the XAXIS statement to have the order you want.

 

http://documentation.sas.com/?docsetId=grstatproc&docsetTarget=p07m2vpyq75fgan14m6g5pphnwlr.htm&docs...

 

proc sgplot data=sashelp.cars;
xaxis values=("GMC" "Honda" "Hyundai") 
   offsetmin=0.2 offsetmax=0.2;
scatter x=make y=mpg_city; 
run;

PS. please take some time to go through your historical posts and mark them as answered/solved with the correct response tagged.

 


@mrdlau wrote:

I'm generating a simple vbar chart with the Y axis being counts, and x axis being ranges that I created as text (i.e "0 to 5%", "5.01 to 10%" etc).

 

When I plot the chart,  my X axis is out of order.  it'll go "0 to 5%", "10 to 15%", "5 to 10%".  How do I set the order in this scenario where the x axis is text?



Proc sgplot data=gridwork.data;
vbar dist/ response=counts;
xaxis label=distribution;
yaxis label='counts;

run;
quit;

 

Ask a Question
Discussion stats
  • 1 reply
  • 61 views
  • 1 like
  • 2 in conversation