# SAS Boxplot – Explore the Major Types of Boxplots in SAS

Job-ready Online Courses: Click, Learn, Succeed, Start Now!

In the last tutorials, we learned how to create SAS histograms,Â pie 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:

#### PROC SGPANEL and SGPLOT Procedures

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.

Syntax-

```PROC SGPLOTÂ  DATA=DATASET;
Â Â Â Â Â Â Â Â  VBOX VARIABLE / category = VARIABLE;
RUN;
PROC SGPANELÂ  DATA=DATASET;;
PANELBY VARIABLE;
Â  VBOX VARIABLE> / category = VARIABLE;
RUN;```

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.

Technology is evolving rapidly!

SAS boxplot without any category:

Â Example-

```proc sgplot data=mylib.employee;
Â vbox salary;
Â run;```

A boxplot with the category:

Example-

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

Â

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

Example-

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

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

Example-

```proc sgpanel data=sashelp.heart;Â  Â Â
panelby sex / columns=1;Â
hbox cholesterol / category=ageatstart ;
title â€˜ Cholestrol by Sex and Age Groupâ€™;
Â run;```

## Summary

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.

Your 15 seconds will encourage us to work even harder

DataFlair Team

The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.

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