Calculating Percentiles with SAS

Deepanshu Bhalla Add Comment

In SAS, you can calculate percentiles using PROC UNIVARIATE procedure.

Important options used for calculating percentile in PROC UNIVARIATE

  1. PCTLPTS : Specifies percentile levels
  2. PCTLPRE : Specifies one or more prefixes to create the variable names for the variables that contain the PCTLPTS= percentiles.
  3. PCTLNAME : Specifies one or more suffixes to create the variable names for the variables that contain the PCTLPTS= percentiles.
Example 1 : Percentile calculation for a variable

The following SAS code calculates the 90th and 99.5th percentile of variable 'a' from the dataset 'abcd' and saves the result to a dataset named 'outdata'.

proc univariate data = abcd noprint;
var a;
output out=outdata PCTLPTS = 90 99.5 PCTLPRE = a;
run;
Example 2 : Percentile calculation for multiple variables

The following SAS code calculates the 99th percentile of variable 'a', 'b' and 'c' from the dataset 'abcd' and saves the result to a dataset named 'outdata'.

proc univariate data = abcd noprint;
var a b c;
output out=outdata PCTLPTS = 99 PCTLPRE = a b c PCTLNAME = _P99;
run;
Calculating Percentiles in SAS

Important Points :

  1. If you specify 3 variables in var statement (var a b c) and only 1 prefix in PCTPRE, SAS will create percentile for only 1 variable that is mentioned first in the var statement.
  2. If the number of PCTLNAME= values is fewer than the number of percentiles or if you omit PCTLNAME=, PROC UNIVARIATE uses the percentile as the suffix to create the name of the variable that contains the percentile.
Example 3 : Series of percentile levels

The following SAS code calculates percentiles from 0 to 5 by 0.5 increments and from 95 to 100 by 0.5 increments for variable 'c' from the dataset 'abcd' and saves the result to a dataset named 'outdata'.

proc univariate data = abcd noprint;
var c;
output out=outdata PCTLPTS = 0 to 5 by 0.5 , 95 to 100 by 0.5 PCTLPRE = P;
run;
How to Get Percentiles in a Tabular Format

The PROC STDIZE procedure is used to find out percentiles in a tabular format. You don't need to specify prefix as original variable names will be used in the output dataset.

proc stdize data=sashelp.class PctlMtd=ORD_STAT outstat=outdata pctlpts=5,95;
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 Percentiles with SAS"
Next → ← Prev