I'm trying to make a bar chart where I can specify the order of X_A X_B and so on.
It looks like the default is alphabetical order.
I would also like to reorder the bars as well; such as the order of E, Q, R, T, U, W.
ods graphics / width=10in height=5in;
title '[P]in X';
proc sgplot data=Narwhal.Narwhal_Data (where=(Dependant_V Contains 'X'));
vbar Dependant_V / response=N_Concentration group=Experiment_Group groupdisplay=cluster
stat=mean limitstat=clm;
xaxis /*display=(nolabel noticks)*/ label="Package";
yaxis grid label="Concentration (pines/apples)";
run;
Hello @Kedarnath_M ,
On the xaxis - statement you need the
option.
Or on the VBAR statement you need the
option.
Good luck,
Koen
Hello @Kedarnath_M ,
On the xaxis - statement you need the
option.
Or on the VBAR statement you need the
option.
Good luck,
Koen
Hello,
with the VALUES=(“string-list”) option on the xaxis statement:
proc sgplot data=sashelp.heart;
vbar smoking_status /
response=ageatdeath
stat=mean;
run;
proc sgplot data=sashelp.heart;
vbar smoking_status /
response=ageatdeath
stat=mean
datalabel=Smoking_Status;
xaxis values=("Moderate (6-15)" "Non-smoker" "Heavy (16-25)" "Very Heavy (> 25)");
run;
/* end of program */
Koen
My bad should have specified; I got the first part with the Value= option
title '[P]in X';
proc sgplot data=Narwhal.Narwhal_Data (where=(Location Contains 'X'));
vbar Dependant_V / response=N_Concentration group=Experiment_Group groupdisplay=cluster
stat=mean limitstat=clm alpha=.05 ;
xaxis /*display=(nolabel noticks)*/ label="Package"
values=('X_A' 'X_C' 'X_D' 'X_E' 'X_B' 'X_F');
yaxis grid label="Concentration (pines/apples)";
run;
I meant for the second part where I can control the order of Q W E R T U Experimental_Group Variable order manually. This is without using the Categoryorder= option since that option orders the groups by itslef.
the part circled in red
Padding some blank before it.
data have; length Dependant_V $ 80 ; set Narwhal.Narwhal_Data; if Dependant_V='E' then Dependant_V =' E'; if Dependant_V='Q' then Dependant_V =' Q'; if Dependant_V='R' then Dependant_V =' R'; run; title '[P]in X'; proc sgplot data=have (where=(Dependant_V Contains 'X'));
Thank you Koen and KSharp! that worked
At first I was confused because the letters wouldn't show up in the work.have data set at first. The length statement should have allowed there to be more characters in the column. When I ran proc contents I saw the format allowed only one character and so I had to go in and change that. I'm still new to SAS😅.
data work.have;
length Experiment_Group $ 10;
format Experiment_Group $ char10.;
set Narwhal.Narwhal_Data;
if Experiment_Group='Q' then Experiment_Group=' Q';
if Experiment_Group='W' then Experiment_Group=' W';
if Experiment_Group='E' then Experiment_Group=' E';
if Experiment_Group='R' then Experiment_Group=' R';
if Experiment_Group='T' then Experiment_Group=' T';
if Experiment_Group='U' then Experiment_Group='U';
run;
PROC CONTENTS DATA=have;
/* Open the LISTING destination and assign the LISTING style to the graph */
*ods listing style=listing;
ods graphics / width=10in height=5in;
title '[P]in X';
proc sgplot data=work.have (where=(Dependant_V Contains 'X'));
vbar Dependant_V / response=N_Concentration group=Experiment_Group groupdisplay=cluster
stat=mean limitstat=clm;
xaxis /*display=(nolabel noticks)*/ label="Package"
values=('X_A' 'X_C' 'X_D' 'X_E' 'X_B' 'X_F');
yaxis grid label="Concentration (pines/apples)";
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.