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;
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.
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.