Solved
Contributor
Posts: 68

# How to calculate the mean of a number of variables in one simple statement?

Hi guys,

If I have 100 numeric variables and I'd like to calculate the average while creating a new variable Mean, is there a simple statement that I can use in the data step instead of typing the variable names one by one and then calculate the average?

Thank you.

Accepted Solutions
Solution
‎08-30-2014 06:06 PM
Posts: 1,270

## Re: How to calculate the mean of a number of variables in one simple statement?

If I understand it correctly, you are trying to mean across the variables. May be this can generate the desired output.

data want;

set have;

array list{*} _numeric_;

mean=mean(of list{*});

run;

All Replies
Solution
‎08-30-2014 06:06 PM
Posts: 1,270

## Re: How to calculate the mean of a number of variables in one simple statement?

If I understand it correctly, you are trying to mean across the variables. May be this can generate the desired output.

data want;

set have;

array list{*} _numeric_;

mean=mean(of list{*});

run;

Posts: 5,482

## Re: How to calculate the mean of a number of variables in one simple statement?

Look into SAS Variable Lists

http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#p0wphcpsfgx6o7n1sjtq...

Functions such as mean can accept variable lists as arguments. For example z = mean( of a--f, of x; will compute the mean of variables a throuhg f in your variable list and of all variables with names starting with x. The variable list notation can save you a lot of typing and make your code more general.

PG

PG
🔒 This topic is solved and locked.