Table of Contents
SAS (Statistical Analysis System) is a powerful software tool used for statistical analysis and data management. It offers various functions and procedures to calculate quartiles, which are measures of central tendency in a dataset. Quartiles are useful for understanding the spread and distribution of data.
To calculate quartiles using SAS, one can use the PROC UNIVARIATE procedure and specify the QUANTILES option. This will generate a list of quartiles, including the first quartile (Q1), second quartile (Q2), and third quartile (Q3). Another option is to use the QUANTILE function, which allows for the calculation of specific quartiles, such as the 25th, 50th, and 75th percentiles.
For example, if we have a dataset of 100 students’ test scores, we can use SAS to calculate the quartiles. The first quartile (Q1) would represent the score at the 25th percentile, meaning 25% of the students scored below this value. The second quartile (Q2), also known as the median, would represent the score at the 50th percentile, with 50% of the students scoring below this value. Lastly, the third quartile (Q3) would represent the score at the 75th percentile, with 75% of the students scoring below this value.
In summary, SAS provides an efficient and reliable method for calculating quartiles and other statistical measures. Its user-friendly interface and extensive documentation make it a popular choice for data analysis in various industries.
Calculate Quartiles in SAS (With Examples)
You can use the following basic syntax to calculate the quartiles for a dataset in SAS:
/*calculate quartile values for variable called var1*/
proc univariatedata=original_data;
var var1;
output out=quartile_data
pctlpts = 25 50 75pctlpre = 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 printdata=original_data;
The following code shows how to calculate the quartiles for the points variable in the dataset
/*calculate quartile values for points*/
proc univariatedata=original_data;
var points;
output out=quartile_data
pctlpts = 25 50 75pctlpre = Q_;
run;
/*view quartiles for points*/
proc printdata=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 univariatedata=original_data;
var points;
by team;
output out=quartile_data
pctlpts = 25 50 75pctlpre = Q_;
run;
/*view quartiles for points*/
proc printdata=quartile_data;
The output table shows the quartile values for the points variable for both teams A and B.
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can I calculate quartiles using SAS and what are some examples of doing so?”. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-calculate-quartiles-using-sas-and-what-are-some-examples-of-doing-so/
stats writer. "How can I calculate quartiles using SAS and what are some examples of doing so?”." PSYCHOLOGICAL SCALES, 26 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-calculate-quartiles-using-sas-and-what-are-some-examples-of-doing-so/.
stats writer. "How can I calculate quartiles using SAS and what are some examples of doing so?”." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-calculate-quartiles-using-sas-and-what-are-some-examples-of-doing-so/.
stats writer (2024) 'How can I calculate quartiles using SAS and what are some examples of doing so?”', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-calculate-quartiles-using-sas-and-what-are-some-examples-of-doing-so/.
[1] stats writer, "How can I calculate quartiles using SAS and what are some examples of doing so?”," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I calculate quartiles using SAS and what are some examples of doing so?”. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
