/* The purpose of this macro is to show how to dynamically process variables in a SAS dataset from left to right, skipping any character variables as well as the variable representing your dependent variable. A univariate measure called the 'importance ratio' is calculated (compliments of Gregg Weldon) by using PROC RANK. The purpose of such a ratio is to enable the analyst to reduce a huge set of predictors down into something more managable. The table called MYTABLE is a summary of these ratios for all variables in the dataset. */ data mydata; input Y VAR1 VAR2 $ VAR3 ; cards; 1 10 yy 4 0 . hg 3 1 30 fd6 2 1 20 gh 1 0 . 65 3 0 20 ws2 . 1 10 dc 2 1 . tg9 2 0 30 yhn 2 1 20 uij 2 1 20 yg 1 0 . jk 3 0 20 lk2 . 1 10 lk 2 1 . uh2 16 0 30 uu 2 1 10 yy 4 0 . hg 13 1 30 fd6 2 1 20 gh 31 0 . 65 3 0 20 ws2 . 1 10 dc 42 1 . tg9 52 0 30 yhn 62 1 20 uij 72 1 20 yg 1 0 . jk 63 0 20 lk2 . 1 10 lk 2 1 . uh2 46 0 30 uu 42 1 10 yy 44 0 . hg 3 1 30 fd6 2 1 20 gh 1 0 . 65 3 0 20 ws2 6. 1 10 dc 62 1 . tg9 62 0 30 yhn 62 1 20 uij 62 1 20 yg 71 0 . jk 73 0 20 lk2 . 1 10 lk 2 1 . uh2 6 0 30 uu 2 1 10 yy 4 0 . hg 3 1 30 fd6 2 1 20 gh 1 0 . 65 3 0 20 ws2 . 1 10 dc 2 1 . tg9 2 0 30 yhn 2 1 20 uij 2 1 20 yg 1 0 . jk 3 0 20 lk2 . 1 10 lk 2 1 . uh2 6 0 30 uu 2 1 10 yy 4 0 . hg 3 1 30 fd6 2 1 20 gh 1 0 . 65 3 0 20 ws2 . 1 10 dc 2 1 . tg9 2 0 30 yhn 2 1 20 uij 2 1 20 yg 1 0 . jk 3 0 20 lk2 . 1 10 lk 2 1 . uh2 6 0 30 uu 2 1 10 yy 4 0 . hg 3 1 30 fd6 2 1 20 gh 1 0 . 65 3 0 20 ws2 . 1 10 dc 2 1 . tg9 2 0 30 yhn 2 1 20 uij 2 1 20 yg 1 0 . jk 3 0 20 lk2 . 1 10 lk 2 1 . uh2 6 0 30 uu 2 1 10 yy 4 0 . hg 3 1 30 fd6 2 1 20 gh 1 0 . 65 3 0 20 ws2 . 1 10 dc 2 1 . tg9 2 0 30 yhn 2 1 20 uij 2 1 20 yg 1 0 . jk 3 0 20 lk2 . 1 10 lk 2 1 . uh2 6 0 30 uu 2 1 10 yy 4 0 . hg 3 1 30 fd6 2 1 20 gh 1 0 . 65 3 0 20 ws2 . 1 10 dc 2 1 . tg9 2 0 30 yhn 2 1 20 uij 2 1 20 yg 1 0 . jk 3 0 20 lk2 . 1 10 lk 2 1 . uh2 6 0 30 uu 2 1 10 yy 4 0 . hg 3 1 30 fd6 2 1 20 gh 1 0 . 65 3 0 20 ws2 . 1 10 dc 2 1 . tg9 2 0 30 yhn 2 1 20 uij 2 1 20 yg 1 0 . jk 3 0 20 lk2 . 1 10 lk 2 1 . uh2 6 0 30 uu 2 1 10 yy 4 0 . hg 3 1 30 fd6 2 1 20 gh 1 0 . 65 3 0 20 ws2 . 1 10 dc 2 1 . tg9 2 0 30 yhn 2 1 20 uij 2 1 20 yg 1 0 . jk 3 0 20 lk2 . 1 10 lk 2 1 . uh2 6 0 30 uu 2 1 10 yy 4 0 . hg 3 1 30 fd6 2 1 20 gh 1 0 . 65 3 0 20 ws2 . 1 10 dc 2 1 . tg9 2 0 30 yhn 2 1 20 uij 2 1 20 yg 1 0 . jk 3 0 20 lk2 . 1 10 lk 2 1 . uh2 6 0 30 uu 2 1 10 yy 4 0 . hg 3 1 30 fd6 2 1 20 gh 1 0 . 65 3 0 20 ws2 . 1 10 dc 2 1 . tg9 2 0 30 yhn 2 1 20 uij 2 1 20 yg 1 0 . jk 3 0 20 lk2 . 1 10 lk 2 1 . uh2 6 0 30 uu 2 ; %macro importance_ratio(mydata,varname,vardep); proc rank data=&mydata out=testrank (keep=&varname &vardep bracket) groups=10 ties=high; ranks bracket; var &varname; run; proc freq data=testrank; table bracket*&vardep /out=freqout; run; proc means data=freqout; var count; by bracket; output out=meanout sum=bsum; run; data importance (keep=varname imptance); length varname $45 ; merge freqout (keep=bracket &vardep count) meanout (keep=bracket bsum) end=done; by bracket; numer+(-count*log(count/bsum)); denom+bsum; if done then do; imptance=-log(numer/denom+.000000000000000000000000001); varname="&varname"; output; end; run; %if &i=1 %then %do; data mytable; set importance; run; %end; %if &i>1 %then %do; proc append base=mytable data=importance;run; %end; %mend importance_ratio; %macro getnames(dsn,vardep); OPTIONS NOTES SOURCE SOURCE2 MPRINT MLOGIC MERROR SYMBOLGEN; %let dsid=%sysfunc(open(&dsn)); %let cnt=(%sysfunc(attrn(&dsid,nvars))); %do i = 1 %to &cnt; %if(%sysfunc(vartype(&dsid,&i)))=N %then %do; %let myname=%sysfunc(varname(&dsid,&i)); %if &myname^=&vardep %then %importance_ratio(mydata,&myname,&vardep); %end; %end; title Summary of Importance Ratio; proc sort data=mytable; by imptance ;run; proc print data=mytable;run; %let rc=%sysfunc(close(&dsid)); %mend getnames; %getnames(mydata,Y);