=adlb;
proc univariate data
var aval;=stats pctlpts=25 40 pctlpre=p;
output out run;
Calculating Quantiles (percentiles) in SAS
Percentiles can be calculated in SAS using the UNIVARIATE procedure. The procedure has the option PCTLDEF
which allows for five different percentile definitions to be used. The default is PCTLDEF=5
, which uses the empirical distribution function to find percentiles.
This is how the 25th and 40th percentiles of aval
in the dataset adlb
could be calculated, using the default option for PCTLDEF
. For quantiles, Q1= 25%, Q2=50%, Q3 = 75%, Q4=100%.
The pctlpre=p
option tells SAS the prefix to use in the output dataset for the percentile results. In the above example, SAS will create a dataset called stats
, containing variables p25
and p40
.