EZ Study

Actuarial Biology Chemistry Economics Calculators Confucius Engineer
Physics
C.S.

Obtain percentiles not automatically calculated?
Compare two univariate outputs in one graph within the same scale

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;

(adsbygoogle = window.adsbygoogle || []).push({});
output  out=data1 pctlpre=P_ pctlpts= 50, 75 to 100 by 5;
/* or output out=data1 pctlpre=P_
pctlpts= 90 95 95.5 96 96.5 97 97.5 98 99 99.5 99.6 99.7 99.8 99.9;  */
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 pctlpre=P_ pctlpts=10 20 30 40 50 60 70 80
85 90 95 95.5 96 96.5 97 97.5 98 98.5 99 99.5 99.6 99.7 99.8 99.9;
run;
proc print data=percentiles1;
run;```

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;

Obs   math_P30   math_P35   math_P40   math_P45
1       46        48.5       49.5        51
Obs   science_P30   science_P35   science_P40    science_P50
1        47           49            50            50    ```
Example 5: Generate 2 histograms' output in the same scale, so it's easier to compare:
```proc univariate data=datain ;
class type1;
histogram var1/ midpoints=0 to 40000 by 1000
HREF=  cHREF=
HREFLABELS=
name='Name what you here'
nrows=2  ncols= 2;
var var1;
quit;```

Acknowledgement: Some tutorial here are from the famous Stat-Lab. at UCLA.

Related links:
Continue to: How to send email in SAS part-I   SAS tutorial home
Back to How to Speed up SAS coding?   Statistics Tutorial Data Mining