Hi Guys,
I have several columns with column names like this:
A B C D E F G.....
what I want to do is to create new columns as A+B,A+C, A+D... and then B+C, B+D, B+E, ... and C+D, C+E, C+F...
I need to repeat this process for many times. Anyone can give me a hint how to write macro on this?
Thank you.
I would use PROC SCORE
Message was edited by: data _null_
You might need macro code (or at least some method to generate macro variables) to make up meaningful names, but to make the sums you can do with straight SAS code.
%let names=a b c d e ;
%let n=%sysfunc(countw(&names));
data want;
set have ;
array single (&n) &names ;
array double (&n,&n) ;
do i=1 to &n ; do j=i+1 to &n ;
double(&i,&j) = single(&i) + single(&j);
end;
run;
Thanks!
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.