In SAS, you can calculate percentiles using PROC UNIVARIATE procedure.
- PCTLPTS : Specifies percentile levels
- PCTLPRE : Specifies one or more prefixes to create the variable names for the variables that contain the PCTLPTS= percentiles.
- 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 :
- 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.
- 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;
Hi ,I am an avid follower of your posts and it has helped a lot in clearing and understanding certain concepts for first of all a BIG BIG THANKS for posting these articles.
ReplyDeleteFor percentiles I would like to share one article which I came across which shares the secret of getting percentile of multiple variable at one go, and also some custom percentiles. Have a look and let me know your thoughts on the same..
http://blogs.sas.com/content/iml/2013/10/23/percentiles-in-a-tabular-format.html