DATA Step, Macro, Functions and more

Side-by-side box plots

Occasional Contributor
Posts: 8

Side-by-side box plots

I have a data set involving a different salaries for different positions at a bunch of different companies.  The different companies are the rows and the different positions (13 total) are the columns.  For the life of me, I cannot figure out how to set up side-by-side box plots for each of the different positions (in the columns).  I actually don't need all thirteen in one graphic, I'd be happy to have just four of them side-by-side. 


I've tried variations of the following code:


proc boxplot data=SalaryByPosition;


"NAME" is just the column header for the names of the companies (there are over a thousand)


The error I get mentions not having enough "panels."


Any help with this would be appreciated!

Super User
Posts: 13,358

Re: Side-by-side box plots

It may help to provide a small example data set with 3 or 4 fake companies and a number of values for the other variables similar to your data so we can make some charts and see which comes close to what you want.

Instructions here: will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.


Your example code would have attempted to create over 1000 plots (one per name) and is the likely problem of not having enough "panels".


One approach may require restructuring your data. See if this comes anywhere close to what you might want.

data junk;
   input name $ position $ value ;
a  SAL_FULL 50000
b  SAL_FULL 52000
c  SAL_FULL 63000
d  SAL_FULL 57000
e  SAL_FULL 77700
f  SAL_FULL 80000
a  SAL_ASC  44000
b  SAL_ASC  48000
c  SAL_ASC  49000
d  SAL_ASC  55000
e  SAL_ASC  67700
f  SAL_ASC  60000

proc sgplot data=junk;
   hbox value/ category=position;

Note that Proc BOXPLOT is pretty old and new enhancements are mostly going to proc SGPLOT/SGPANEL.



ODS GRAPHICS statement would be using to adjust the size of the graphic area and 13 positions, as above, could be quite easy to fit in a single display.

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation