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!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.