2.4 C
London
Friday, December 20, 2024
HomeSASDescriptive Statistics in SASHow to Calculate Quartiles in SAS (With Examples)

How to Calculate Quartiles 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...

You can use the following basic syntax to calculate the quartiles for a dataset in SAS:

/*calculate quartile values for variable called var1*/
proc univariate data=original_data;
    var var1;
    output out=quartile_data
    pctlpts = 25 50 75
    pctlpre = Q_;
run;

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

The following example shows how to use this syntax in practice.

Example: How to Calculate Quartiles in SAS

Suppose we have the following dataset in SAS that contains two variables:

/*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;

The following code shows how to calculate the quartiles for the points variable in the dataset

/*calculate quartile values for points*/
proc univariate data=original_data;
    var points;
    output out=quartile_data
    pctlpts = 25 50 75
    pctlpre = Q_;
run;

/*view quartiles for points*/
proc print data=quartile_data;

Here’s how to interpret the output:

  • The value of the first quartile is 18.5.
  • The value of the second quartile is 25.
  • The value of the third quartile is 30.5.

To calculate the quartile values grouped by the team variable, simply add by team in the proc univariate statement:

/*calculate quartile values for points*/
proc univariate data=original_data;
    var points;
    by team;
    output out=quartile_data
    pctlpts = 25 50 75
    pctlpre = Q_;
run;

/*view quartiles for points*/
proc print data=quartile_data;

The output table shows the quartile values 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 Calculate Percentiles in SAS
How to Use Proc Summary in SAS
How to Create Frequency Tables 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