BookmarkSubscribeRSS Feed
mrdlau
Obsidian | Level 7

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;
1 REPLY 1
Reeza
Super User

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;

 

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 3108 views
  • 1 like
  • 2 in conversation