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

Accepted Solution Solved
Reply
Contributor
Posts: 68
Accepted Solution

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
Trusted Advisor
Posts: 1,203

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;

View solution in original post


All Replies
Solution
‎08-30-2014 06:06 PM
Trusted Advisor
Posts: 1,203

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;

Respected Advisor
Posts: 4,609

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 xSmiley Happy; 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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 192 views
  • 5 likes
  • 3 in conversation