11.8 C
London
Tuesday, May 20, 2025
HomeSASDescriptive Statistics in SASHow to Calculate Mean, Median, & Mode in SAS

How to Calculate Mean, Median, & Mode in SAS

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

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.

Additional Resources

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

How to Calculate Correlation in SAS
How to Identify Outliers in SAS
How to Create Frequency Tables in SAS

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories