BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
csetzkorn
Lapis Lazuli | Level 10

Let us say I have a dataset like so:

 

ID X1 X2
1 1 1
2 1 0

 

Here Id indicates something to be modeled. The 0 and 1 in columns X1 and X2 indicate whether the indepedent varible should be used in the model (0=do not include, 1=include). So the model code to be produced would be:

 

PROC GLMSELECT data=TrainingData;
model DependentVariable
= 
X1
X2
/ selection = stepwise(select=SL choose=AICC);
run;

 

and

 

 

PROC GLMSELECT data=TrainingData;
	model DependentVariable
		= 
		X1
	/ selection = stepwise(select=SL choose=AICC);
run

respectivley. Ideally I would like to invoke a macro given the Id. The Id is then used to write and execute the modeling code. Btw the relvantTrainingData given Id can be easily initialised from anothe dataset. Any ideas how to achieve the above? Thanks!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

If you are planning to use CALL EXECUTE, you don't really need to define a macro.  Here's one way:

 

data _null_;

set have;

call execute('PROC GLMSELECT data=TrainingData;') ;

call execute('model Dependentvariable =') ;

array indeps {*} X1 X2 and a bunch more;

do _n_=1 to dim(indeps);

   if indeps{_n_} = 1 then do;

      varname = vname(indeps{_n_});

      call execute(varname);

   end;

end;

call execute ('/ selection = stepwise(select=SL choose=AICC); run;') ;

run;

 

Obviously it's untested, so it might need to be debugged.

View solution in original post

2 REPLIES 2
Reeza
Super User

1. Create a macro for your regression that takes a variable list

2. In the data step, create a variable that has the values you need, ie 

 

ID X1 X2 Variable_List

1 1 1 X1 X2

2 1 0 X1

 

3. Pass those to the macro using CALL EXECUTE

 

 

 

 

Astounding
PROC Star

If you are planning to use CALL EXECUTE, you don't really need to define a macro.  Here's one way:

 

data _null_;

set have;

call execute('PROC GLMSELECT data=TrainingData;') ;

call execute('model Dependentvariable =') ;

array indeps {*} X1 X2 and a bunch more;

do _n_=1 to dim(indeps);

   if indeps{_n_} = 1 then do;

      varname = vname(indeps{_n_});

      call execute(varname);

   end;

end;

call execute ('/ selection = stepwise(select=SL choose=AICC); run;') ;

run;

 

Obviously it's untested, so it might need to be debugged.

sas-innovate-2024.png

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.

 

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
  • 2 replies
  • 662 views
  • 2 likes
  • 3 in conversation