BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
liyongkai800
Obsidian | Level 7

 

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.

1 ACCEPTED SOLUTION

Accepted Solutions
liyongkai800
Obsidian | Level 7
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;

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

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;
PG
liyongkai800
Obsidian | Level 7

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. 

PGStats
Opal | Level 21

Great find! In the interest of those reading this topic in the future, could you post the code that you ended up using? - Thanks.

PG
liyongkai800
Obsidian | Level 7
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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 715 views
  • 2 likes
  • 2 in conversation