How do you calculate Mean, Median, & Mode in SAS?

In SAS, the mean, median, and mode of a set of data can be calculated using the MEANS, MEDIAN, and MODES procedures, respectively. The MEANS procedure uses the MEAN statement to calculate the arithmetic mean. The MEDIAN procedure uses the MEDIAN statement to calculate the median. The MODES procedure uses the MODE statement to calculate the mode. The PROC MEANS, MEDIAN, and MODES procedures also generate additional statistics, such as standard deviation, skewness, kurtosis, quartiles, etc.


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 print data=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 univariate data=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 univariate data=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 .

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

x