We’re smarter together. Learn from this collection of community knowledge and add your expertise.

Using PROC SGPLOT to Produce Box Plots with Contrasting Colours in SAS

by Contributor EricCai on ‎04-09-2015 01:50 PM - edited on ‎10-05-2015 03:26 PM by Community Manager (270 Views)

The following article was originally published on my blog, The Chemical Statistician.

 

I previously explained the statistics behind box plots and how to produce them in R in a very detailed tutorial.  I also illustrated how to produce side-by-side box plots with contrasting patterns in R.

Here is an example of how to make box plots in SAS using the VBOX statement in PROC SGPLOT.  I modified the built-in data set SASHELP.CLASS to generate one that suits my needs.

The PROC TEMPLATE statement specifies the contrasting colours to be used for different classes.  I also include code for exportingthe result into a PDF file using ODS PDF.  (I used varying shades of grey to allow the contrast to be shown when printed in black and white.)

boxplots

 

There are some very useful SAS documents on the different colours and marker symbols.  There is a separate documentation page colour schemes in SAS/GRAPH programs, and it has a specific section on grey-scale colour codes.

ods path(prepend)          

     work.template(update);

 

proc template;          

     define style mystyle;          

     parent = styles.printerl;

     class graphdata1

          /    color = grayaa                    

               contrastcolor = gray00                    

               markersymbol = 'circle';

     class graphdata2

          /    color = graycc                    

               contrastcolor = grayaa                    

               markersymbol = 'square';          

     end;

run;  

 

data heights;         

     set sashelp.class;          

     if age < 13                    

           then teenager = 'Pre-Teenager';

     else teenager = 'Teenager';

    

     if sex = 'F'                    

               then gender = 'Female';          

      else gender = 'Male';           

      label            gender = 'Gender'                              

                           teenager = 'Age Group';

     keep height gender teenager; run; 

 

 

 

ods pdf file = 'INSERT YOUR DIRECTORY PATH HERE\heights.pdf'          

     notoc style = mystyle;

 

 

proc sgplot          

     data = heights;          

     vbox height /                    

     category = gender                    

     group = teenager;

run;  

 

ods pdf close;

Your turn
Sign In!

Want to write an article? Sign in with your profile.