BookmarkSubscribeRSS Feed
DingDing
Quartz | Level 8

 

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;     

 

 

3 REPLIES 3
Reeza
Super User
If you're testing multiple models and capturing the AIC, which I think you're missing the TABLEOUT option for from a previous question, you may want to use a macro method.

Here's a basic intro on how to do that.

If you're dealing with categorical variables you need to convert them to binary variables or use PROC GLM with them specified as a class variable. If you have time, though you should make the time, the SAS Statistical course is free and will walk you through how to perform a regression and what to look for and how to deal with categorical variables. There are entire courses on this subject so I'm not going to bother trying to explain it here.
DingDing
Quartz | Level 8
Thank you for your response, dear Reeza, but one more thing I want to confirm is that whether my reasoning of the codes is correct for model selection?
PGStats
Opal | Level 21

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.

PG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 912 views
  • 0 likes
  • 3 in conversation