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.
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;
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;
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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.