# Calculating Percentiles with SAS

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
proc univariate data = abcd noprint;
var a;
output out=outdata PCTLPTS = 99.5 PCTLPRE = a;
run;
Example 2 :

Percentile calculation for multiple variables
proc univariate data = abcd noprint;
var a b c;
output out=outdata PCTLPTS = 99 PCTLPRE = a b c PCTLNAME = _P99;
run;

2 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
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;