SAS: How to Use PROC MEANS with CLASS Statement


You can use PROC MEANS to calculate summary statistics for each numeric variable in a dataset in SAS.

You can also use the CLASS statement within PROC MEANS to calculate summary statistics, grouped by one or more categorical variables.

The following examples show how to use the CLASS statement in practice with the following dataset in SAS that contains information about various basketball players:

/*create dataset*/
data my_data;
    input team $ position $ points assists;
    datalines;
A Guard 14 4
A Guard 22 6
A Guard 24 9
A Forward 13 8
A Forward 13 9
A Guard 10 5
B Guard 24 4
B Guard 22 6
B Forward 34 2
B Forward 15 5
B Forward 23 5
B Guard 10 4
;
run;

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

Example 1: Using PROC MEANS without CLASS Statement

The following code shows how to use PROC MEANS without the CLASS statement:

/*calculate summary statistics for numeric variables*/
proc means data=my_data;
run;

By default, PROC MEANS produces summary statistics for each numeric variable in the dataset.

Example 2: Using PROC MEANS with One Variable in CLASS Statement

The following code shows how to use PROC MEANS with the CLASS statement to specify that summary statistics should be computed for the numeric variables, grouped by the team variable:

/*calculate summary statistics for numeric variables, grouped by team*/
proc means data=my_data;
    class team;
run;

The output now shows the summary statistics for each numeric variable, grouped by the unique values in the team column.

For example, the first row in the output shows the summary statistics for the points variable only for the players on team A.

Example 3: Using PROC MEANS with Multiple Variables in CLASS Statement

The following code shows how to use PROC MEANS with the CLASS statement to specify that summary statistics should be computed for the numeric variables, grouped by the team and position variables:

/*calculate summary statistics for numeric variables, grouped by team and position*/
proc means data=my_data;
    class team position;
run;

The output now shows the summary statistics for each numeric variable, grouped by the unique values in the team and position columns.

For example, the first row in the output shows the summary statistics for the points variable only for the players on team A in a position of Forward.

Additional Resources

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

How to Calculate Descriptive Statistics in SAS
How to Create Frequency Tables in SAS
How to Calculate Percentiles in SAS

Featured Posts

Leave a Reply

Your email address will not be published. Required fields are marked *