To find the mean by group in SAS, you can use PROC MEANS and specify by group in the CLASS statement. You can find the mean of multiple variables and group by multiple groups with PROC MEANS.

```
data example;
input group $ value;
datalines;
A 1
A 2
A 3
B 4
B 5
B 6
C 7
C 8
;
run;
proc means data=example mean;
class group;
variable value;
run;
```

You can also output this dataset with the OUTPUT statement.

```
data example;
input group $ value;
datalines;
A 1
A 2
A 3
B 4
B 5
B 6
C 7
C 8
;
run;
proc means data=example mean;
class group;
variable value;
output out=mean_by_group mean(value)=;
run;
/* Output */
group _TYPE_ _FREQ_ value
0 8 4.5
A 1 3 2
B 1 3 5
C 1 2 7.5
```

Use the NWAY option if you only want to create a dataset with the means by group (instead of the entire dataset, for example).

```
data example;
input group $ value;
datalines;
A 1
A 2
A 3
B 4
B 5
B 6
C 7
C 8
;
run;
proc means data=example mean nway;
class group;
variable value;
output out=mean_by_group mean(value)=;
run;
/* Output */
group _TYPE_ _FREQ_ value
A 1 3 2
B 1 3 5
C 1 2 7.5
```

When working with data, the ability to summarize and aggregate your data in different ways is very valuable.

One such case is if you want to find the mean of certain variables of your data.

In SAS, PROC MEANS is a procedure which allows you to create summaries of your data and allows you to calculate things like the mean, mean, min, max, etc. of a variable.

You can use PROC MEANS to find the mean of variables by group using the CLASS statement.

Below is a simple example of how you can use PROC MEANS to find means by group in SAS.

```
data example;
input group $ value;
datalines;
A 1
A 2
A 3
B 4
B 5
B 6
C 7
C 8
;
run;
proc means data=example mean;
class group;
variable value;
run;
```

## How to Find Mean of Variable By Multiple Groups in SAS with PROC MEANS

If you want to find the mean of a variable by multiple groups in SAS, you can add variables to the PROC MEANS CLASS statement.

Below shows you a simple example of calculating the mean across multiple groups in SAS with PROC MEANS.

```
data example;
input group1 $ group2 $ value;
datalines;
A D 1
A D 2
A E 3
B E 4
B E 5
B F 6
C F 7
C F 8
;
run;
proc means data=example mean;
class group1 group2;
variable value;
run;
```

## How to Find Mean of Multiple Variables by Group in SAS with PROC MEANS

If you want to get the mean of multiple values by group in SAS, you can add variables to the PROC MEANS VARIABLE statement.

Below shows you a simple example of finding the mean of multiple variables by group in SAS with PROC MEANS.

```
data example;
input group $ value1 value2;
datalines;
A 1 2
A 2 3
A 3 4
B 4 5
B 5 6
B 6 7
C 7 8
C 8 9
;
run;
proc means data=example mean;
class group;
variable value1 value2;
run;
```

Hopefully this article has been useful for you to learn how to find the mean of variables by groups using PROC MEANS in SAS.

## Leave a Reply