Programming the statistical procedures from SAS

iterative macro to drop variables from model with high VIF systemically

Reply
New Contributor
Posts: 2

iterative macro to drop variables from model with high VIF systemically

Hello,

 

I am trying to write a macro that will drop variables from my regression model, one at a time, based on VIF. I want it to run, drop the highest VIF variable, run again, drop the highest, then repeat until all VIFs are 5 or less. Please help. My data set is named "save.dafinal", dependent variable is "gaaverage", and independent variables are saved as a macro variable "%radius1demo". Thanks.

Grand Advisor
Posts: 16,897

Re: iterative macro to drop variables from model with high VIF systemically

Your question is coming across as "Do my work" rather than "I need help", In general, if you need someone to do work, you hire a consultant.

What have you tried? Where are you having issues?
New Contributor
Posts: 2

Re: iterative macro to drop variables from model with high VIF systemically

Oh. Sorry. I'm new to posting in a community. Usually I just google my way to an answer from the SAS website, but this one has been rough. This is what I've done thus far.

 

%MACRO MULTICOLLINEARITY(YVAR,FIELDS,MAX_VIF);

ods _all_ close;

%put Running with &fields;

 

PROC REG DATA=save.dafinal;

MODEL &YVAR = &FIELDS / VIF COLLIN NOINT;

ODS OUTPUT PARAMETERESTIMATES=PAREST2;

RUN;

quit;

 

proc sort data=parest2;

by descending varianceinflation;

run;

data _null_;

set parest2(obs=1);

if varianceinflation > &max_vif then do;

fields_run = tranwrd("&fields",trim(variable),' ');

if not missing(fields_run) then do;

call_string = cats('%multicollinearity(',"&yvar.,",fields_run,",&max_vif.)");

call execute(call_string);

end;

end;

else do;

put "Stopped with Max VIF:" variable "=" varianceinflation;

end;

run;

ods preferences;

%MEND MULTICOLLINEARITY;

%MULTICOLLINEARITY(yvar=gaaverage, fields=%radius1demovars,MAX_VIF=5)

Ask a Question
Discussion stats
  • 2 replies
  • 285 views
  • 0 likes
  • 2 in conversation