Hi all,
I am a healthcare investigator and am looking to have a model I am trying to make include interaction terms. My only problem is that when I include the interaction effects into the MODEL statement, I sometimes will get the interaction effects without the main effects in the model. I want to know how I might be able to keep the main effects in the model along with an interaction effect.
Here is my code:
%macro elasticnet (l2_cust_low, l2_cust_high);
ods select CoefficientPanel ASEPlot ParameterEstimates FitStatistics;
proc glmselect data=data.resilience3 plots=all seed=712;
title1 "SELECTION=ELASTICNET(L2SEARCH=GOLDEN L2LOW= &l2_cust_low L2HIGH= &l2_cust_high))";
title2 "Primary Analysis";
partition fraction(test=0.3);
class sex(ref='0') nonhisp_black(ref='0') nonhisp_white(ref='0') hispanic(ref='0') Married(ref='0') single(ref='0')
ged_hsdiploma(ref='0') Assoc_Bachelor(ref='0') graduate(ref='0') Tetra_abc(ref='0') para_abc(ref='0')
sleep(ref='0') pain_interfere2(ref='0') Healthsts_pos(ref='0') fyear_1(ref='0') fyear_5(ref='0') fyear_10(ref='0')
fyear_15(ref='0') fyear_20_25(ref='0') fyear_30plus(ref='0');
model BRsTScr2 = age sex nonhisp_black nonhisp_white hispanic Married single
ged_hsdiploma Assoc_Bachelor graduate Tetra_abc para_abc
fyear_5 fyear_10 fyear_15 fyear_20_25 fyear_30plus
BSFBMTS2 BSFSCTS2 BSFFMoTS2 sleep pain pain_interfere2 Healthsts_pos
BCHPITot2 BCHMbTot2 BCHOpTot2 BCHSocIn2 depression life_sat pain*depression /
SELECTION=ELASTICNET(L2SEARCH=GOLDEN L2LOW= &l2_cust_low L2HIGH= &l2_cust_high choose = cv)
cvmethod=split(10) hierarchy=none showpvalues;
run;
%MEND elasticnet;
%elasticnet(0,0.1);
%elasticnet(0.1,0.2);
%elasticnet(0.2,0.3);
%elasticnet(0.3,0.4);
%elasticnet(0.4,0.5);
%elasticnet(0.5,0.6);
%elasticnet(0.6,0.7);
%elasticnet(0.7,0.8);
%elasticnet(0.8,0.9);
%elasticnet(0.9,1);
Any and all help will be greatly appreciated!
For some selection methods, you can use HIERARCHY=SINGLE or INCLUDE=n to force terms to stay in the model. However, the elastic net method does not support those options.
I think the best you can do is to run the procedure twice. The first time, use the SELECTION=ELASTICNET method to choose effects for the model. Then run the procedure again using SELECTION=NONE to fit the model, but force the main effects that you want in the model. The first run creates the _GLSIND macro variable, which contains the selected effects. Therefore, if the pain*depression effect is selected, the second model will be
MODEL BRsTScr2 = pain depression &_GLSIND / selection=none;
For your example, in your
For some selection methods, you can use HIERARCHY=SINGLE or INCLUDE=n to force terms to stay in the model. However, the elastic net method does not support those options.
I think the best you can do is to run the procedure twice. The first time, use the SELECTION=ELASTICNET method to choose effects for the model. Then run the procedure again using SELECTION=NONE to fit the model, but force the main effects that you want in the model. The first run creates the _GLSIND macro variable, which contains the selected effects. Therefore, if the pain*depression effect is selected, the second model will be
MODEL BRsTScr2 = pain depression &_GLSIND / selection=none;
For your example, in your
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.