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

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

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.

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.

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;

Share Share Tweet