How do you calculate the mean, median, and mode in SAS? 2

How do you calculate the mean, median, and mode in SAS?

Calculating the mean, median, and mode in SAS involves using specific procedures and functions within the SAS software. The mean, also known as the average, can be calculated by using the MEAN function, which takes the values of a variable and calculates their sum, then divides it by the number of observations. The median, or the middle value in a dataset, can be obtained by using the MEDIAN function, which orders the values and returns the middle value if there is an odd number of values, or the average of the two middle values if there is an even number. The mode, or the most frequently occurring value, can be determined using the MODE function, which returns the value with the highest frequency. By utilizing these functions in SAS, accurate calculations of the mean, median, and mode can be achieved for any given dataset.

Calculate Mean, Median, & Mode in SAS


You can use proc univariate to quickly calculate the mean, median, and mode of variables in SAS.

This procedure uses the following basic syntax:

proc univariate data=my_data;
run;

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

Example: Calculate Mean, Median & Mode for All Variables

Suppose we have the following dataset in SAS:

/*create dataset*/
data my_data;
    input team $ points rebounds assists;
    datalines;
A 25 10 8
B 18 4 5
C 18 7 10
D 24 12 4
E 27 11 5
F 30 8 7
G 12 8 5
;
run;

/*view dataset*/
proc printdata=my_data;

We can use the following code to calculate the mean, median and mode for all variables in our dataset:

/*calculate mean, median, mode for each variable in my_data*/
proc univariatedata=my_data;
run;

This code produces the following output:

1. Mean, Median & Mode for Points Variable

We can see:

  • The mean points value is 22.
  • The median points value is 24.
  • The mode points value is 18.

2. Mean, Median & Mode for Rebounds Variable

  • The mean rebounds value is 8.57.
  • The median rebounds value is 8.
  • The mode rebounds value is 8.

3. Mean, Median & Mode for Assists Variable

We can see:

  • The mean assists value is 6.28.
  • The median assists value is 5.
  • The mode assists value is 5.

If you’d like to only calculate the mean, median and mode for one specific variable, you can use the following syntax:

/*calculate mean, median, and mode only for points variable*/
proc univariatedata=my_data;    var points;
run;

The mean, median and mode values will only be calculated for the points variable.

Note: You can find the complete documentation for PROC UNIVARIATE .

Additional Resources

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

Cite this article

stats writer (2024). How do you calculate the mean, median, and mode in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-do-you-calculate-the-mean-median-and-mode-in-sas/

stats writer. "How do you calculate the mean, median, and mode in SAS?." PSYCHOLOGICAL SCALES, 30 Jun. 2024, https://scales.arabpsychology.com/stats/how-do-you-calculate-the-mean-median-and-mode-in-sas/.

stats writer. "How do you calculate the mean, median, and mode in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-do-you-calculate-the-mean-median-and-mode-in-sas/.

stats writer (2024) 'How do you calculate the mean, median, and mode in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-do-you-calculate-the-mean-median-and-mode-in-sas/.

[1] stats writer, "How do you calculate the mean, median, and mode in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How do you calculate the mean, median, and mode in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

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