BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chouchou
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

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

2 REPLIES 2
stat_sas
Ammonite | Level 13

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;

PGStats
Opal | Level 21

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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