How to create Box Plots in SAS

Last updated on Sep 13 2022
Nitin Pawar

Table of Contents

How to create Box Plots in SAS

A Boxplot is graphical representation of groups of numerical data through their quartiles. Box plots may also have lines extending vertically from the boxes (whiskers) indicating variability outside the upper and lower quartiles. The bottom and top of the box are always the first and third quartiles, and the band inside the box is always the second quartile (the median). In SAS a simple Boxplot is created using PROC SGPLOT and paneled boxplot is created using PROC SGPANEL.

Please note that we create the data set named CARS1 in the first example and use the same data set for all the subsequent data sets. This data set remains in the work library till the end of the SAS session.

Syntax

The basic syntax to create a boxplot in SAS is −

PROC SGPLOT DATA = DATASET;
VBOX VARIABLE / category = VARIABLE;
RUN;

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

Following is the description of parameters used −

• DATASET − is the name of the dataset used.

• VARIABLE − is the value used to plot the Boxplot.

Simple Boxplot

In a simple Boxplot we choose one variable from the data set and another to form a category. The values of the first variable are categorized in as many number of groups as the number of distinct values in the second variable.

Example

In the below example we choose the variable horsepower as the first variable and type as the category variable. So we get boxplots for the distribution of values of horsepower for each type of car.

PROC SQL;

create table CARS1 as

SELECT make, model, type, invoice, horsepower, length, weight

FROM

SASHELP.CARS

WHERE make in ('Audi','BMW')

;

RUN;

PROC SGPLOT DATA = CARS1;

VBOX horsepower

/ category = type;

title 'Horsepower of cars by types';

RUN;

When we execute the above code, we get the following output −

sas 30

Boxplot in Vertical Panels

We can divide the Boxplots of a variable into many vertical panels(columns). Each panel holds the boxplots for all the categorical variables. But the boxplots are further grouped using another third variable which divides the graph into multiple panels.

Example

In the below example we have paneled the graph using the variable ‘make’. As there are two distinct values of ‘make’ so we get two vertical panels.

PROC SGPANEL DATA = CARS1;
PANELBY MAKE;
VBOX horsepower / category = type;
title 'Horsepower of cars by types';
RUN;

When we execute the above code, we get the following output −

sas 31

Boxplot in Horizontal Panels

We can divide the Boxplots of a variable into many horizontal panels(rows). Each panel holds the boxplots for all the categorical variables. But the boxplots are further grouped using another third variable which divides the graph into multiple panels. In the below example we have paneled the graph using the variable ‘make’. As there are two distinct values of ‘make’ so we get two horizontal panels.

PROC SGPANEL DATA = CARS1;
PANELBY MAKE / columns = 1 novarname;
VBOX horsepower / category = type;
title 'Horsepower of cars by types';
RUN;

When we execute the above code, we get the following output −

sas 32

So, this brings us to the end of blog. This Tecklearn ‘How to create Box Plots in SAS’ blog helps you with commonly asked questions if you are looking out for a job in SAS. If you wish to learn SAS and build a career in Data Analytics domain, then check out our interactive, SAS Training for SAS BASE CertificationTraining, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

SAS Training for SAS BASE Certification

SAS Training for SAS BASE Certification Training

About the Course

SAS Certification Training is intended to make you an expert in SAS programming and Analytics. You will be able to analyse and write SAS code for real problems, learn to use SAS to work with datasets, perform advanced statistical techniques to obtain optimized results with Advanced SAS programming. In this SAS online training course, you will also learn SAS macros, Machine Learning, PROC SQL, procedure, statistical analysis and decision trees. You will also work on real-life projects and prepare for the SAS Certified Base Programmer certification exam. Upon the completion of this SAS online training, you will have enough proficiency in reading spreadsheets, databases, using SAS functions for manipulating this data and debugging it.

Why Should you take SAS Training?

• The average salary for a Business Intelligence Developer skilled in SAS is $100k (PayScale salary data)

• SAS, Google, Facebook, Twitter, Netflix, Accenture & other MNCs worldwide are using SAS for their Data analysis activities and advance their existing systems.

• SAS is a Leader in 2017 Gartner Magic Quadrant for Data Science Platform.

What you will Learn in this Course?

Introduction to SAS

• Introduction to SAS

• Installation of SAS

• SAS windows

• Working with data sets

• Walk through of SAS windows like output, search, editor etc

SAS Enterprise Guide

• How to read and subset the data sets

• SET Statement

• Infile and Infile Options

• SAS Format -Format Vs Informat

SAS Operators and Functions

• Using Variables

• Defining and using KEEP and DROP statements

• Output Statement

• Retain Statement

• SUM Statement

Advanced SAS Procedures

• PROC Import

• PROC Print

• Data Step Vs Proc

• Deep Dive into Proc

Customizing Datasets

• SAS Arrays

• Useful SAS Functions

• PUT/INPUT Functions

• Date/Time Functions

• Numeric Functions

• Character Functions

SAS Format and SAS Graphs

• SAS Format statements

• Understanding PROC GCHART, various graphs, bar charts: pie, bar

Sorting Techniques

• NODUP

• NODUKEY

• NODUP Vs NODUKEY

Data Transformation Function

• Character functions, numeric functions and converting variable type

• Use functions in data transformation

Deep Dive into SAS Procedures, Functions and Statements

• Find Function

• Scan Function

• MERGE Statement

• BY Statement

• Joins

• Procedures Vs Function

• Where Vs If

• What is Missover

• NMISS

• CMISS

PROC SQL

• SELECT statement

• Sorting of Data

• CASE expression

• Other SELECT statement clauses

• JOINS and UNIONS

Using SAS Macros

• Benefits of SAS Macros

• Macro Variables

• Macro Code Constituents and Macro Step

• Positional Parameters to Macros

Got a question for us? Please mention it in the comments section and we will get back to you.

 

 

 

 

 

 

 

 

 

 

 

 

0 responses on "How to create Box Plots in SAS"

Leave a Message

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