Calculating Quartiles in SAS

Deepanshu Bhalla Add Comment

This tutorial explains how to calculate quartiles in SAS, along with examples.

The PROC UNIVARIATE procedure is used to calculate quartiles in SAS.

Calculating Quartiles for a Variable

The following SAS code calculates first, second and third quartile of variable 'height' from the dataset 'class' and saves the result to a dataset named 'outdata'.

proc univariate data = sashelp.class noprint;
var height;
output out=outdata PCTLPTS = 25 50 75 PCTLPRE = P;
run;

In the PCTLPTS option, 25 refers to 25th percentile i.e. first quartile. 50 refers to 50th percentile i.e. second quartile. 75 refers to 75th percentile i.e. third quartile.

PCTLPRE refers to one or more prefixes to create the variable names for the quartiles.

Calculating Quartiles in SAS
Calculating Quartiles for Multiple Variables

The following SAS code calculates first, second and third quartile for variables 'height' and 'weight'.

proc univariate data = sashelp.class noprint;
var height weight;
output out=outdata PCTLPTS = 25 50 75 PCTLPRE = height_ weight_;
run;

Please note that we have to specify two prefixes in the PCTLPRE option for two variables.

Getting Quartiles in Tabular Form

You can use the PROC STDIZE procedure to get quartiles in tabular form in SAS.

proc stdize data=sashelp.class PctlMtd=ORD_STAT outstat=outdata pctlpts=25,50,75;
var height weight;
run;
Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

Post Comment 0 Response to "Calculating Quartiles in SAS"
Next → ← Prev