29.8 C
London
Saturday, June 28, 2025
HomeSASDescriptive Statistics in SASHow to Calculate Percentiles in SAS (With Examples)

How to Calculate Percentiles in SAS (With Examples)

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

Here are the three most common ways to calculate the percentiles of a dataset in SAS:

Method 1: Calculate One Specific Percentile Value

/*calculate 70th percentile value for var1*/
proc univariate data=original_data;
    var var1;
    output out=percentile_data
    pctlpts = 70
    pctlpre = P_;
run;

Method 2: Calculate Multiple Specific Percentile Values

/*calculate 70th, 80th, and 90th percentile value for var1*/
proc univariate data=original_data;
    var var1;
    output out=percentile_data
    pctlpts = 70 80 90
    pctlpre = P_;
run;

Method 3: Calculate Percentiles by Group

/*sort original data by var2*/
proc sort data=original_data;
    by var2;
run;

/*calculate percentiles for var1 grouped by var2*/
proc univariate data=original_data;
    var var1;
    by var2;
    output out=percentile_data
    pctlpts = 70, 80, 90
    pctlpre = P_;
run;

Note: The pctlpts statement specifies which percentiles to calculate and the pctlpre statement specifies the prefix to use for the percentiles in the output.

The following examples show how to use each method with the following dataset in SAS:

/*create dataset*/
data original_data;
    input team $ points;
    datalines;
A 12
A 15
A 16
A 21
A 22
A 25
A 29
A 31
B 16
B 22
B 25
B 29
B 30
B 31
B 33
B 38
;
run;

/*view dataset*/
proc print data=original_data;

Example 1: Calculate One Specific Percentile Value

The following code shows how to calculate the 70th percentile for the points variable:

/*calculate 70th percentile value for points*/
proc univariate data=original_data;
    var points;
    output out=percentile_data
    pctlpts = 70
    pctlpre = P_;
run;

/*view results*/
proc print data=percentile_data;

The value at the 70th percentile turns out to be 30.

Example 2: Calculate Multiple Specific Percentile Values

The following code shows how to calculate the values at the 70th, 80th, and 90th percentiles for the points variable:

/*calculate 70th, 80th, and 90th percentile value for points*/
proc univariate data=original_data;
    var points;
    output out=percentile_data
    pctlpts = 70 80 90
    pctlpre = P_;
run;

Here’s how to interpret the output:

  • The value at the 70th percentile is 30.
  • The value at the 80th percentile is 31.
  • The value at the 90th percentile is 33.

Example 3: Calculate Percentiles by Group

The following code shows how to calculate the values at the 70th, 80th, 90th, and 95th percentile for the points variable, grouped by the team variable:

/*sort original data by team*/
proc sort data=original_data;
    by team;
run;

/*calculate percentiles for points grouped by team*/
proc univariate data=original_data;
    var points;
    by team;
    output out=percentile_data
    pctlpts = 70, 80, 90 95
    pctlpre = P_;
run;

The output table shows the values for the 70th, 80th, 90th, and 95th percentile for the points variable for both teams A and B.

Additional Resources

The following tutorials explain how to perform other common tasks in SAS:

How to Use Proc Summary in SAS
How to Create Frequency Tables in SAS
How to Calculate Correlation in SAS

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories