Here's another solution to creating interaction variables that avoids macro programming.
Create a variable list of the main effects of interest from proc contents, then accumulate all of the interaction variable creation data step statements into one long macro variable.
For example, to create the interaction variables green_red_int, black_red_int, and white_red_int, run the following code:
data test;
input id green black white red;
cards;
1 2.1 10 20 30
2 3.2 40 50 60
3 4.3 70 80 90
;
proc contents data=test out=varlist(keep=varnum name) order=varnum;
run;
proc sort data=varlist;
by varnum;
run;
data varlist;
set varlist;
if varnum in(2:4);
run;
data _null_;
length allvars $90;
retain allvars;
set varlist end=eof;
allvars =trim(left(allvars))||' '||trim(name)||'_red_int = '||trim(name)||'*red;';
if eof then call symput('interactions', allvars);
run;
%put &interactions;
data test2;
set test;
&interactions;
run;
... View more