<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to iteratively run macros while toggling on/off multiple macro inputs? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-iteratively-run-macros-while-toggling-on-off-multiple/m-p/926554#M364614</link>
    <description>&lt;P&gt;First I would double-check that you can't use GLMSELECT or one of the similar procedures to do the model selection without having to write a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, if you go the macro route, I would write a macro to run one regression that you could call like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LRModel(var=x1 x2 x3, outcome=y, data=mydata, strata=Z)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Main difference vs your design is that I would pass a list of independent variables, rather than a switch for each possible variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That macro could run a regression, and output a dataset with the likelihood ratio tests.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once that is working, you can write an outer %DRIVER macro. &amp;nbsp;That macro would also have a VAR parameter where you would pass a list of independent variables. &amp;nbsp;Then it would have a %do %until loop, and inside the loop would be a call to %LRMODEL. Inside the loop after calling %LRMODEL it would generate the next list of independent variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, I'm not clear on what models you want to generate. &amp;nbsp;If you had just 3 predictors, are you saying would would want to generate just 3 models:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LRModel(var=     x2 x3, outcome=y, data=mydata, strata=Z)
%LRModel(var=x1      x3, outcome=y, data=mydata, strata=Z)
%LRModel(var=x1 x2     , outcome=y, data=mydata, strata=Z)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or are you doing some sort of stepwise regression where after running these, if you decide the model with X1 and X3 is best, you then want to run a model with just X1 and a model with just X3?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 May 2024 00:26:36 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2024-05-01T00:26:36Z</dc:date>
    <item>
      <title>How to iteratively run macros while toggling on/off multiple macro inputs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-iteratively-run-macros-while-toggling-on-off-multiple/m-p/926552#M364612</link>
      <description>&lt;P&gt;Broad context: I'm doing model selection, and can't use the easy automatic statements because I have a bunch of dummy coded variables + want to use likelihood ratio test. However, because I will be doing a bunch of model selection, I do want to try to automate the process as much as possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far what I've done is to create a macro to run the model where I can toggle each variable of interest on/off, and my thinking was that I could run a model, then toggle off a variable, store the outputs of both models, and then stack p values and sort to determine which variable to toss next until they are all significant. However, if anyone has any other strategies I am also open, I'm sure there are also other, probably better, ways to accomplish this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current macro call looks something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%LRModel(var1,var2,var3,var4,var5,dataset,strata,outcome);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If var1-var5 are 1 then the model includes that variable, so a full model looks like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%LRModel(1,1,1,1,1,dataset,strata,outcome);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and then nested models might look like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%LRModel( ,1,1,1,1,dataset,strata,outcome); &lt;BR /&gt;%LRModel(1, ,1,1,1,dataset,strata,outcome); &lt;BR /&gt;%LRModel(1,1, ,1,1,dataset,strata,outcome); &lt;BR /&gt;%LRModel(1,1,1, ,1,dataset,strata,outcome); &lt;BR /&gt;%LRModel(1,1,1,1, ,dataset,strata,outcome); &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The blank can also be anything that's not a 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm stuck on how I can iteratively call the full model and then the nested models, automatically without having to write out each macro call, although I feel like there's got to be a way to to do this. Any help would be much appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 23:59:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-iteratively-run-macros-while-toggling-on-off-multiple/m-p/926552#M364612</guid>
      <dc:creator>epialy</dc:creator>
      <dc:date>2024-04-30T23:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to iteratively run macros while toggling on/off multiple macro inputs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-iteratively-run-macros-while-toggling-on-off-multiple/m-p/926554#M364614</link>
      <description>&lt;P&gt;First I would double-check that you can't use GLMSELECT or one of the similar procedures to do the model selection without having to write a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, if you go the macro route, I would write a macro to run one regression that you could call like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LRModel(var=x1 x2 x3, outcome=y, data=mydata, strata=Z)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Main difference vs your design is that I would pass a list of independent variables, rather than a switch for each possible variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That macro could run a regression, and output a dataset with the likelihood ratio tests.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once that is working, you can write an outer %DRIVER macro. &amp;nbsp;That macro would also have a VAR parameter where you would pass a list of independent variables. &amp;nbsp;Then it would have a %do %until loop, and inside the loop would be a call to %LRMODEL. Inside the loop after calling %LRMODEL it would generate the next list of independent variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, I'm not clear on what models you want to generate. &amp;nbsp;If you had just 3 predictors, are you saying would would want to generate just 3 models:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LRModel(var=     x2 x3, outcome=y, data=mydata, strata=Z)
%LRModel(var=x1      x3, outcome=y, data=mydata, strata=Z)
%LRModel(var=x1 x2     , outcome=y, data=mydata, strata=Z)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or are you doing some sort of stepwise regression where after running these, if you decide the model with X1 and X3 is best, you then want to run a model with just X1 and a model with just X3?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2024 00:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-iteratively-run-macros-while-toggling-on-off-multiple/m-p/926554#M364614</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-05-01T00:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to iteratively run macros while toggling on/off multiple macro inputs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-iteratively-run-macros-while-toggling-on-off-multiple/m-p/926645#M364664</link>
      <description>&lt;P&gt;Sorry, I totally forgot to specify- I'm doing backwards selection and starting with a full model and dropping one variable at a time. I need to calculate a LR ratio test for the comparison between the full model and the model with 1 variable dropped, for every combination to determine which variable to drop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using proc phreg and time dependent variables, so I have dummy coding within the model. I was using the toggles to control both the list of independent variables, and the segment that writes the dummy coding e.g.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc phreg data=&amp;amp;dataset multipass outest=m3;
  class &amp;amp;cl  /param=ref order=formatted ref=first;
  model (startage,endage)*&amp;amp;outcome(0) = 
	%if &amp;amp;var1.=1 %then %do; td1 td2 td3 %end;
	/ rl type3 ties=exact;

  %if &amp;amp;var1.=1 %then %do;
  if 0&amp;lt;= followup &amp;lt;365.25 then do;
      td1=0; td2=0; td3=0; end;
	%end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is super simplified and just one variable out of many but hopefully it gives the idea. I don't think I'd be able to just pass a list of variables, because "td1 td2 td3" have to be treated as the same variable. This is the reason I can't use the automatic selection methods either.&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2024 17:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-iteratively-run-macros-while-toggling-on-off-multiple/m-p/926645#M364664</guid>
      <dc:creator>epialy</dc:creator>
      <dc:date>2024-05-01T17:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to iteratively run macros while toggling on/off multiple macro inputs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-iteratively-run-macros-while-toggling-on-off-multiple/m-p/926694#M364688</link>
      <description>&lt;P&gt;Well, now I'm more confused. I've used PHREG a bit, but didn't realize it allowed programming statements. : )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you like your macro parameterization, then that's enough for me to happy with it.&amp;nbsp; I stand by my general suggestion of getting the PHREG macro to work like you want to run one model, and calculate whatever test statistic you want for that model, and then writing a %Driver macro that will generate calls to your PHREG macro until whatever stopping condition you want.&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2024 21:14:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-iteratively-run-macros-while-toggling-on-off-multiple/m-p/926694#M364688</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-05-01T21:14:07Z</dc:date>
    </item>
  </channel>
</rss>

