sas - loop through variables to create interaction terms -


i seek loop through variables (can contained in macro variable or data set) create macro variable interaction terms can use in regression. here example.

let’s original variables in macro variable.

%let predictors = age sex bmi; 

i seek loop through these variables , create macro variable can use in regression.

in first iteration, have age. seek create:

% interactions = age sex bmi sex*age bmi*age 

fit regression.

then use sex in next iteration.

% interactions = age sex bmi age*sex bmi*sex; 

and on. thanks!

note sure how using this, simple %do loop should handle request.

%macro test(predictors); %local n j ; %let n=%sysfunc(countw(&predictors)); %do i=1 %to &n;   %let interactions=&predictors;   %do j=1 %to &n;     %if &i^=&j %then %let interactions=        &interactions %scan(&predictors,&i)*%scan(&predictors,&j)     ;   %end;   %put &=i &=interactions; %end; %mend ; %test(age sex bmi); 

which produces list log.

i=1 interactions=age sex bmi age*sex age*bmi i=2 interactions=age sex bmi sex*age sex*bmi i=3 interactions=age sex bmi bmi*age bmi*sex 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -