Proc Boxplot -- sort the 'groups' another way

Regular Contributor
Posts: 212

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.


Nicholas Kormanik

Super Contributor
Posts: 543

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


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;



proc sql;

    create table max_ht as

    select max(height) as max_ht, age

    from temp

    group by age;


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;


proc sort data = want;by age;

data really_want;

    merge temp want;

    by age;


*modified order;

proc sort data = really_want;by new_age;

proc boxplot data = really_want;

    plot height * new_age;


Please let me know if you have questions.

(and provide sample data)

Good luck!


Regular Contributor
Posts: 212

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.


Super Contributor
Posts: 543

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

Unfortunately, I agree.

I am not aware of such options.



Ask a Question
Discussion stats
  • 3 replies
  • 2 in conversation