# How to 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 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

We can see:

• 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 here.