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;

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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