how to create subsets of variables in SAS using a criteria -
i trying run regression 2 independent variables automatically selected (meeting criterion) variable list. example, variable list is:
var1 var2 var3 var4 var5
i trying run 10 regressions using pattern:
outcomevar = var1 var2 outcomevar = var1 var3 . . . outcomevar = var2 var3 . . . outcomevar = var4 var5
i trying generate macro contain loop automatically build these regressions. trying use %scan
function generate loop cannot formulate criteron variable selection.
a nested loop 1 option :
%macro combi ; %let nvar = 5 ; %do x = 1 %to %eval(&nvar - 1) ; %do y = %eval(&x + 1) %to &nvar ; %let outcomevar = var&x var&y ; %put &outcomevar ; /* else outcomevar */ %end ; %end ; %mend ; %combi ;
if variables aren't numbered , sequential, you'd need adopt different approach :
%macro combi ; %let varlist = somevar thisvar thatvar varx vary ; %let nvar = %sysfunc(countw(&varlist)) ; %do x = 1 %to %eval(&nvar - 1) ; %do y = %eval(&x + 1) %to &nvar ; %let outcomevar = %sysfunc(scan(&varlist,&x)) %sysfunc(scan(&varlist,&y)) ; %put &outcomevar ; /* else outcomevar */ %end ; %end ; %mend ; %combi ;
Comments
Post a Comment