I'd like to use boxplot to make comparisons between three variables, say, Nh, Nt, Nc. I'd like to see the three boxplots side by side in the order: Nh, Nt, Nc. But the output displayed the boxplots in the order: Nc, Nh, Nt (alphabetically). How can I change the order to the one I want? Thanks!
With the SGPLOT procedure (SAS 9.2), you can set DISCRETEORDER=data on the XAXIS statement to get data order.
data box; do x='Nh', 'Nt', 'Nc'; do i=1 to 10; y=10*ranuni(2); output; end; end; run; ods listing; ods graphics / reset width=5in height=3in imagename='BoxOrder'; proc sgplot data=box; vbox y / category=x; xaxis display=(nolabel) discreteorder=data; run;
Sorry I didn't make it clear. First, I'd like to use proc boxplot. Second, I'd like to control the order of the boxes in the boxplots. Not necessarily Nh, Nt, Nc, but maybe Nt, Nc, Nh. Would you please tell me how to do that using proc boxplot? Thanks.
You could manipulate your data so that the values of your boxes are in alphabetical order, and then create a format so that what displays is still the meaningful names, like 'Nt', 'Nc', and 'Nh'. For example:
do x='V3', 'V1', 'V2';
do i=1 to 10;
'V1' = 'Nt'
'V2' = 'Nc'
'V3' = 'Nh';
proc sort data=box;
ods graphics / reset width=5in height=3in imagename='BoxOrder';
proc boxplot data=box;
format x $myboxval.;
You can pad white blank before value of variables to customize your order.
Make sure that your variable has long enough to hold these white blanks.
data box; length x $ 8; do x='Nt', 'Nc', 'Nh'; do i=1 to 10; y=10*ranuni(2); output; end; end; run; data box; set box; if x='Nt' then x=' Nt'; else x='Nc' then x=' Nc'; run; ods listing; ods graphics / reset width=5in height=3in imagename='BoxOrder'; footnote ''; proc boxplot data=box; plot y*x=i; run;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.