### SAS FAQ How do I obtain percentiles not automatically calculated?

In proc univariate the default output contains a list of percentiles including the 1st, 5th, 10th, 25th, 50th, 75th, 90th, 95th, 99th and 100th percentile. In most situations these percentiles are sufficient but at times it becomes necessary to obtain other percentiles. Percentiles that are not included in the default output are easily obtained through the output statement in proc univariate.

Example 1
Creating a data set with the default name data1 which contains the 50th, 75th, 80th, 85th, 90th, 95th, and 100th percentile in the variables P_50, P_75, P_80, P_85, P_90, P_95, P_100. The pctlpre option in the output statement allows us to specify the prefix of all the variables to be created followed by the number corresponding to the percentile calculated. This option is obligatory when using the pctlpts option. The name of the data set was set by SAS because the out option in the output statement was not used. (The next data set created by SAS would be data2, then data3 and so forth.)

proc univariate data=hsb noprint;
var write;
output pctlpre=P_ pctlpts= 50, 75 to 100 by 5;
run;
proc print data=data1;
run;

Obs    P_50    P_75    P_80    P_85    P_90    P_95    P_100
1      54      60      62      62      65      65       67

Example 2
The proc univariate calculates the 33rd and 45th percentiles for the variable write. These values are stored in the variables P33 and P45 which are saved in the data set percentiles1. Note: The out option in the output statement allows us to specify the name of the data set to be created.

proc univariate data=hsb noprint;
var write;
output out=percentiles1 pctlpts=33 45 pctlpre=P;
run;
proc print data=percentiles1;
run;

Obs    P33     P45
1      49    53.5

Example 3
The proc univariate calculates the 33rd and 45th percentiles for the variables math and science. These values are stored in the variables math33, science33, math45 and science45 which are saved in the data set percentiles2. We specified two prefixes to be used in the pctlpre option since we are calculating the percentiles for two different variables.

proc univariate data=hsb noprint;
var math science;
output out=percentiles2 pctlpts=33 45 pctlpre=math science;
run;
proc print data=percentiles2;
run;

Obs    math33    math45    science33    science45
1       48        51          47           50

Example 4
The proc univariate calculates the 30th, 35th, 40th and 45th percentiles for the variables math and science. These values are stored in the variables math_P30, science_P30, math_P35, science_P35, math_P40, science_P40, math_P45 and science_P45 which are saved in the data set percentiles3.

proc univariate data=hsb noprint;
var math science;
output out=percentiles3 pctlpts=30 to 45 by 5 pctlpre=math_ science_
pctlname=P30 P35 P40 P45;
run;
proc print data=percentiles3;
run;
science_   science_   science_   science_
Obs   math_P30   math_P35   math_P40   math_P45      P30        P35        P40        P45
1       46        48.5       49.5        51         47         49         50         50

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.