BookmarkSubscribeRSS Feed
echoli
Obsidian | Level 7

Hi All,

 

I am trying to complete a boxplot, but the group order in figure is not what I want. As in the figure below, I want the group order is E9.5, E10.5, E11.5. And here is my code:

 

proc sgplot data=lab;
vbox lin__1 / category=group group=group gropdisplay=cluster
lineattrs=(pattern=solid) whiskerattrs=(pattern=solid);
xaxis display=(nolabel);
yaxis grid;
run;

 

Any way can change it?

 Thanks,

Chen

 sgplot_1.png

3 REPLIES 3
Rick_SAS
SAS Super FREQ

Lots of options, but a simple way is to sort the data in the data set and then use

the GROUPORDER=DATA option on the VBOX statement.

Rick_SAS
SAS Super FREQ

Another option is to use CATEGORY= instead of GROUP=.  Then you can set the values by using the XAXIS statement, as this example shows:


proc sgplot data=sashelp.cars;
   vbox mpg_city / category=origin;
   xaxis type=discrete values=('USA' 'Asia' 'Europe');
run;
djrisks
Barite | Level 11

Hi Chen,

 

You can try out the grouporder option within vbox. Another options that will definitely work is to create a format based on the variable group. So you can create a numeric column based on group, i.e. groupn, and that will have the values, 1, 2 and 3. Then you can use that numeric variable in the plot: i.e. 

 

proc format;

  value grouporder 1 = "E9.5"

                              2 = "E10.5"

                              3 = "E11.5";

run;

 

proc sort data = lab;

  by groupn;

run;

 

proc sgplot data=lab;
vbox lin__1 / category=groupn group=groupn gropdisplay=cluster
lineattrs=(pattern=solid) whiskerattrs=(pattern=solid);
xaxis display=(nolabel);
yaxis grid;

format groupn grouporder.;
run;

 

 

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
  • 3 replies
  • 9767 views
  • 1 like
  • 3 in conversation