How can I display the interquartile range (IQR) in PROC MEANS using SAS? 2

How can I display the interquartile range (IQR) in PROC MEANS using SAS?

PROC MEANS is a statistical procedure in SAS used for summarizing data and calculating various descriptive statistics. To display the interquartile range (IQR) in PROC MEANS, the following steps can be followed:
1. The data must be sorted in ascending order using the SORT procedure in SAS.
2. The IQR can then be calculated by finding the difference between the 75th and 25th percentiles of the data using the PCTLDEF option in PROC MEANS.
3. The result can be displayed in the output by using the OUTPUT statement in PROC MEANS.
This method allows for the easy and accurate display of the IQR in PROC MEANS, providing valuable information about the spread of the data.

SAS: Display IQR in PROC MEANS


You can use PROC MEANS to calculate summary statistics for variables in SAS.

By default, PROC MEANS does not display the interquartile range (IQR) as one of the summary statistics but you can use the QRANGE statement to include the IQR in the output:

proc meansdata=my_data N Mean QRANGE Std Min Max;
    var points;
run;

This particular example calculates the total number of observations, mean, interquartile range, standard deviation, minimum and maximum value for a variable called points.

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

Example: Display IQR in PROC MEANS in SAS

Suppose we have the following dataset in SAS that contains information about various basketball players:

/*create dataset*/
data my_data;
    input team $ points assists;
    datalines;
A 10 2
A 17 5
A 17 6
A 18 3
A 15 0
B 10 2
B 14 5
B 13 4
B 29 0
B 25 2
C 12 1
C 30 1
C 34 3
C 12 4
C 11 7
;
run;

/*view dataset*/
proc printdata=my_data;

Suppose we use PROC MEANS to calculate summary statistics for the points variable in the dataset:

/*calculate summary statistics for points variable*/
proc meansdata=my_data;
    var points;
run;

descriptive statistics in SAS using PROC MEANS

By default, PROC MEANS calculates the following descriptive statistics:

  • N: The total number of observations
  • Mean: The mean value of points
  • Std Dev: The standard deviation of points
  • Minimum: The minimum value of points
  • Maximum: The maximum value of points

Notice that the IQR is not included in the output.

We can use the following syntax to include the IQR in the output:

/*calculate summary statistics for points and include IQR*/
proc meansdata=my_data N Mean QRANGE Std Min Max;
    var points;
run;

Notice that the output now includes the interquartile range value for the points variable.

We can see that the IQR for the points variable turns out to be 13.

Recall that the IQR represents the difference between the 75th percentile and the 25th percentile for a given variable.

If you’d like to see the values for these percentiles, you can include P25 and P75 in the PROC MEANS procedure:

/*calculate summary statistics for points and include IQR*/
proc meansdata=my_data N Mean P25 P75 QRANGE Std Min Max;
    var points;
run;

The output now includes the 25th percentile, the 75th percentile, and the interquartile range for the points variable.

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

Cite this article

stats writer (2024). How can I display the interquartile range (IQR) in PROC MEANS using SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-display-the-interquartile-range-iqr-in-proc-means-using-sas/

stats writer. "How can I display the interquartile range (IQR) in PROC MEANS using SAS?." PSYCHOLOGICAL SCALES, 24 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-display-the-interquartile-range-iqr-in-proc-means-using-sas/.

stats writer. "How can I display the interquartile range (IQR) in PROC MEANS using SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-display-the-interquartile-range-iqr-in-proc-means-using-sas/.

stats writer (2024) 'How can I display the interquartile range (IQR) in PROC MEANS using SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-display-the-interquartile-range-iqr-in-proc-means-using-sas/.

[1] stats writer, "How can I display the interquartile range (IQR) in PROC MEANS using SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How can I display the interquartile range (IQR) in PROC MEANS using SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top