turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- How to calculate the mean of a number of variables...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-30-2014 05:41 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to chouchou

08-30-2014 06:06 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to chouchou

08-30-2014 06:06 PM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to chouchou

08-30-2014 08:52 PM

Look into SAS Variable Lists

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