This example, which uses the Belts
data set from the previous example, illustrates how to save percentiles in an output data set. The UNIVARIATE procedure automatically
computes the 1st, 5th, 10th, 25th, 75th, 90th, 95th, and 99th percentiles for each variable. You can save these percentiles
in an output data set by specifying the appropriate keywords. For example, the following statements create an output data
set named PctlStrength
, which contains the 5th and 95th percentiles of the variable Strength
:
proc univariate data=Belts noprint; var Strength Width; output out=PctlStrength p5=p5str p95=p95str; run;
The output data set PctlStrength
is listed in Output 4.8.1.
Output 4.8.1: Listing of Output Data Set PctlStrength
Analysis of Speeding Data |
Obs | p95str | p5str |
---|---|---|
1 | 1284.34 | 1126.78 |
You can use the PCTLPTS=, PCTLPRE=, and PCTLNAME= options to save percentiles not automatically computed by the UNIVARIATE
procedure. For example, the following statements create an output data set named Pctls
, which contains the 20th and 40th percentiles of the variables Strength
and Width
:
proc univariate data=Belts noprint; var Strength Width; output out=Pctls pctlpts = 20 40 pctlpre = Strength Width pctlname = pct20 pct40; run;
The PCTLPTS= option specifies the percentiles to compute (in this case, the 20th and 40th percentiles). The PCTLPRE= and PCTLNAME= options build the names for the variables containing the percentiles. The PCTLPRE= option gives prefixes for the new variables, and the PCTLNAME= option gives a suffix to add to the prefix. When you use the PCTLPTS= specification, you must also use the PCTLPRE= specification.
The OUTPUT statement saves the 20th and 40th percentiles of Strength
and Width
in the variables Strengthpct20
, Widthpct20
, Strengthpct40
, and Weightpct40
. The output data set Pctls
is listed in Output 4.8.2.
Output 4.8.2: Listing of Output Data Set Pctls
Analysis of Speeding Data |
Obs | Strengthpct20 | Widthpct20 | Strengthpct40 | Widthpct40 |
---|---|---|---|---|
1 | 1165.91 | 2.9595 | 1199.26 | 2.995 |
A sample program for this example, uniex06.sas, is available in the SAS Sample Library for Base SAS software.