20 C
London
Wednesday, July 23, 2025
HomeSASDescriptive Statistics in SASSAS: How to Use Proc Univariate by Group

SAS: How to Use Proc Univariate by Group

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 in SAS with the by statement to calculate descriptive statistics for each numeric variable in a dataset, grouped by a particular variable.

This procedure uses the following basic syntax:

proc univariate data=my_data normal;
    by group_variable;
run;

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

Example: Proc Univariate by Group 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 rebounds;
    datalines;
A 12 8
A 12 8
A 12 8
A 23 9
A 20 12
A 14 7
A 14 7
B 20 2
B 20 5
B 29 4
B 14 7
B 20 2
B 20 2
B 20 5
;
run;

/*view dataset*/
proc print data=my_data;

We can use proc univariate with the by statement to calculate descriptive statistics for the points and rebounds variables, grouped by the team variable:

proc univariate data=my_data;
    by team;
run;

This procedure will produce the following results:

  • Descriptive statistics for points for team A
  • Descriptive statistics for rebounds for team B
  • Descriptive statistics for points for team A
  • Descriptive statistics for rebounds for team B

Here is what the descriptive statistics looks like for the points variable for team A:

If you only want to calculate descriptive statistics for one specific variable grouped by another variable, then you can use the var statement.

For example, you can use the following syntax to calculate descriptive statistics only for the points variable, grouped by the team variable:

proc univariate data=my_data;
    var points;
    by team;
run;

Feel free to specify as many variables as you’d like in both the var and by statements to calculate descriptive statistics for whichever variables you’d like.

Additional Resources

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

How to Use Proc Univariate for Normality Tests in SAS
How to Use Proc Summary in SAS
How to Use Proc Tabulate 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