Say I use proc glmselect to select some variables, and then want to use those variables to retrain the model. Is there any way
to store those subsets?
Step1 obtain the subsets.
proc glmselect data=mydata;
by id;
model y=x1 x2 x3 x4 x5/selection=lasso;
run;
selected subsets:
For id=1, x1,x3 are selected.
For id=2, x2,x4 are selected.
Step2
proc genmod data=mydata;
by id
model y= ???(how)/dist=...;
run;
How to store the subsets and complete step 2?
Thanks.
Here is the example I follow, you may use it as the reference.
Also, the link is https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_glmselect_sect021.htm
where you can find more details.
proc glmselect data=one; by byVar; class classVar; model y = classVar x1|x2|x3|x4|x5 @2 / selection=stepwise(stop=aicc); output out=glmselectOutput; run;
%macro LSMeansAnalysis; %do i=1 %to &_GLSNUMBYS; title1 "Analysis Using the Selected Model for BY group number &i"; title2 "Selected Effects: &&_GLSIND&i"; ods select LSMeans; proc glm data=glmselectOutput(where = (_BY_ = &i)); class classVar; model y = &&_GLSIND&i; lsmeans classVar; run;quit; %end; %mend; %LSMeansAnalysis;
Here is an example using call execute
proc sort data=sashelp.heart out=heart; by sex; run;
/* Run the parameter selection procedure and capture the selections with ODS */
proc glmselect data=heart;
by sex;
model weight = ageAtStart height / selection=lasso;
ods output selectedEffects=se;
run;
/* define a macro for each regression, sending the parameter estimates to
separate datasets*/
%macro myGenmod(by,effects);
title "Model for Sex=&by";
proc genmod data=heart;
where sex="&by";
by sex; /* Adds Sex to the parameter estimates dataset */
model weight = &effects;
ods output parameterEstimates=pe_&by;
run;
%mend myGenmod;
/* Call the macro for every by-group */
data _null_;
set se;
effects = transtrn(effects, "Intercept", "");
length line $200;
line = cats('%myGenmod(', Sex, ",", effects, ");");
put line;
call execute(line);
run;
/* Concatenate parameter estimates datasets */
data pe;
set pe_: ;
run;
title "Parameter estimates for both sexes";
proc print data=pe noobs; run;
I found _glsind1,_glsind2, ....._glsindn are the macro variables storing the selected subsets that can be used directly in step 2. But still thanks for the help.
Great find! In the interest of those reading this topic in the future, could you post the code that you ended up using? - Thanks.
Here is the example I follow, you may use it as the reference.
Also, the link is https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_glmselect_sect021.htm
where you can find more details.
proc glmselect data=one; by byVar; class classVar; model y = classVar x1|x2|x3|x4|x5 @2 / selection=stepwise(stop=aicc); output out=glmselectOutput; run;
%macro LSMeansAnalysis; %do i=1 %to &_GLSNUMBYS; title1 "Analysis Using the Selected Model for BY group number &i"; title2 "Selected Effects: &&_GLSIND&i"; ods select LSMeans; proc glm data=glmselectOutput(where = (_BY_ = &i)); class classVar; model y = &&_GLSIND&i; lsmeans classVar; run;quit; %end; %mend; %LSMeansAnalysis;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.