BookmarkSubscribeRSS Feed

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

Started ‎04-09-2015 by
Modified ‎10-05-2015 by
Views 1,339

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.)



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)          



proc template;          

     define style mystyle;          

     parent = styles.printerl;

     class graphdata1

          /    color = grayaa                    

               contrastcolor = gray00                    

               markersymbol = 'circle';

     class graphdata2

          /    color = graycc                    

               contrastcolor = grayaa                    

               markersymbol = 'square';          




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;



ods pdf close;

Version history
Last update:
‎10-05-2015 03:26 PM
Updated by:



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Labels
Article Tags