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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.