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!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.