SAS Boxplot – Explore the Major Types of Boxplots in SAS

FREE Online Courses: Elevate Your Skills, Zero Cost Attached - Enroll Now!

In the last tutorials, we learned how to create SAS histogramspie charts, bar charts and scatter plots for analysis and representation of data. Now, we will look at another interesting way in which we can present data, that is SAS boxplots.

We will look at how to create a Boxplot in SAS and the different types of box plots in SAS Programming Language. Lastly, we will discuss some SAS Boxplot examples and SAS Sgplot & SAS gplot boxplot in detail.

So, let’s start the tutorial.

What is a SAS Boxplot?

A BOXPLOT in SAS creates side-by-side box-and-whiskers plots of measurements organized in groups. A box-and-whiskers plot displays the mean, quartiles, and minimum and maximum observations for a group. Below image shows how a SAS boxplot looks like:

SAS Box Plot Example


We saw how sgplot is used to create bar charts in SAS, the same can be used to create box plots too. In addition to this, we also have the PROC SGPANEL to create box plots in SAS.


         VBOX VARIABLE / category = VARIABLE;

The PROC SGPANEL statement identifies the data set that contains the plot variables.

Simple Boxplot in SAS

In this type of SAS boxplot, we choose a variable from a dataset that represents a category and other variables whose values get categorized in as many numbers of groups as the number of distinct values in the second variable.

SAS boxplot without any category:


proc sgplot data=mylib.employee;
 vbox salary;


Simple BoxPlot in SAS - Without Category

A boxplot with the category:


proc sgplot data=mylib.employee;
vbox salary/ category=gender;


Simple Box Plot in SAS - With Category

SAS Boxplot in Vertical Panels

This SAS boxplot is a group using another third variable which divides the graph into multiple panels. We can divide the boxplots of a variable into many vertical panels(columns). Each panel holds the box plots for all the categorical variables.


proc sgpanel data=mylib.employee;
panelby jobcat / rows=1 columns=3 ;
vbox salary / category= gender;


SAS Box plot in Vertical Panels

SAS Boxplot in Horizontal Panels

This is very similar to vertical panels Boxplot. In this SAS boxplot, a variable is divided into rows. Like vertical, in this also we categorize the data upon a third variable.


proc sgpanel data=sashelp.heart;    
panelby sex / columns=1; 
hbox cholesterol / category=ageatstart ;
title ‘ Cholestrol by Sex and Age Group’;


SAS Boxplot in Horizontal Panels


In this SAS tutorial, we understood what is a boxplot in SAS, how can we create a SAS box plot and what are the ways of presenting a box plot. Stay tuned for more interesting topics and for any queries, post your doubts in the comments section below.

Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google

follow dataflair on YouTube

2 Responses

  1. Susanna says:

    What is the code used to create the boxplot in #2?

  2. Helal Mobasher says:

    is there a way to add an overall plot in any of the graphs? for example, salary by gender so the plot starts with an overall salary followed by salary by male & female.

Leave a Reply

Your email address will not be published. Required fields are marked *