## Proc Boxplot -- sort the 'groups' another way

Regular Contributor
Posts: 238

# Proc Boxplot -- sort the 'groups' another way

The default (and maybe only) way of sorting the 'groups' is alphabetical, ascending.

I have many panels (or screenfulls) of the resulting boxplots, though.  And it's really difficult to ascertain which are higher.

I'd like to be able to sort the boxplots by another criteria other than alphabetical.

Like..., sort by the value of the highest observation.

Or..., sort by the value of the 75th percentile.

Does anyone know if such can be done?  And how?

The more specific and detailed your suggestions, the better.

Thanks,

Nicholas Kormanik

Super Contributor
Posts: 543

## Re: Proc Boxplot -- sort the 'groups' another way

Hi.

Here is a rather tedious way,but it does accomplish (I think) what you want:

*select the max of the variable you are interesting in plotting (the max of your Y-axis variable);

*and select the X-axis variable w/o any modifications;

*for my example I use age and height from sashelp.class -- not the best data set to use but to make the point;

*original plot - no modifications;

proc sort data = sashelp.class out = temp;by age;

proc boxplot data = temp;

plot height * age;

run;quit;

*----------------------------------------;

proc sql;

create table max_ht as

select max(height) as max_ht, age

from temp

group by age;

quit;

proc sort data = max_ht;by max_ht;run;

data want;

set max_ht;

new_age = _n_; *we will eventually use this variable to create the box plots;

run;

proc sort data = want;by age;

data really_want;

merge temp want;

by age;

run;

*modified order;

proc sort data = really_want;by new_age;

proc boxplot data = really_want;

plot height * new_age;

run;quit;

Please let me know if you have questions.

(and provide sample data)

Good luck!

Anca.

Regular Contributor
Posts: 238

## Re: Proc Boxplot -- sort the 'groups' another way

Thanks, Anca, for your work above.

At the very least you are corroborating that there is no simple way to change the default sort.

Nicholas

Super Contributor
Posts: 543

## Re: Proc Boxplot -- sort the 'groups' another way

Unfortunately, I agree.

I am not aware of such options.

Regards,

Anca.

Discussion stats
• 3 replies
• 824 views
• 3 likes
• 2 in conversation