Working with the following toy dataset, I'm trying to create code which will automatically calculate two-way interaction variables for a given set of main effects named "black", "white" and "red".
data test;
input black white red;
cards;
10 20 30
40 50 60
70 80 90
;
run;
proc contents data=test out=varlist(keep=name);
run;
data _null_;
length allvars $20;
retain allvars ' ';
set varlist end=eof;
allvars = trim(left(allvars))||' '||left(name);
if eof then call symput('varlist', allvars);
run;
%put &varlist;
/*
black red white
*/
%macro create_interaction_vars();
data test;
set test;
%let separator_s =%str( );
%do i=1 %to 3;
%let v&i = %scan(&varlist, &i, %str( ));
%end;
%do i=1 %to 3;
%do j=1 %to 3;
%if &i <= &j %then %goto continue;
data test;
set test;
w&i.&j = &&v&i.*&&v&j;
rename w&i.&j = "&v&i._&v&j_int";
run;
%continue:
%end;
%end;
run;
%mend;
%create_interaction_vars();
I have no problems creating interactions variables named w12, w13, and w23. However, I'd like the interaction terms to have more informative names created from the main effect terms such as: "white_red_int", "white_black_int", and "red_black_int", but am getting tied up when it comes to concatenating two macro variable names.
Any help is much appreciated, thanks!
Robert
... View more