Dear all,
I am not very clear on how to apply forward stepwise procedure by using AIC in SAS to select a model, and of which is highly recommended by my professor, so I want to try to apply it.
e.g.performing forward stepwise procedure in model selection.
model (1): y=x1
model (2): y=x1+x2
My reasoning for the codes: (1) performing forward stepwise selection and getting AIC value of model (1)
(2) performing forward stepwise selection and getting AIC value of model (2)
(3) comparing the AIC value output form model (1) and (2), and choosing the model corresponding to a lower AIC value
Could anybody check whether my thingking path is correct or not?
If it is correct, I think the codes are also not well-formulated, because actually I have five more predictor variables. If checking the AIC value one by one, there will be too much repeated work. In this case, I will consider writting a macro, but I don't know how to do currently, could anyone offer me a similiar example on writting a macro for a model selection?
If my thingking path is wrong, could anyone tell me the correct solution of using stepwise procedure to make a model selection by checking the AIC?
Another question is that, in my dataset, there are both categorical variables and continuous variables and I want to make a model selection containing both cases of variables. My initial idea is to convert categorical variables to numeric, for example, male=0; female=1, but after convertion, the log came up with:
WARNING: No variables specified for an SSCP matrix. Execution terminating.
I suspect my solution is wrong, so could anyone offer me some information on how to deal with categorical variable in a multiple regression model?
*performing forward stepwise selection and getting AIC value of model (1) proc reg data=have_1 outest=want_1; model y = x1 /selection=forward aic; run; *print AIC value; proc print data=want_1; run; *performing forward stepwise selection and getting AIC value of model (2) proc reg data=have_2 outest=want_2; model y = x1, x2 /selection=forward aic; run; *print AIC value; proc print data=want_2; run;
You can do forward model selection based on AIC with proc glmselect. Name your categorical variables in the class statement, as in this outline:
proc glmselect data=have;
class gender;
model y = x1 x2 gender / selection=forward(choose=aicc);
run;
Check the documentation for many more options.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.