<?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: macro for looping through variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-for-looping-through-variables/m-p/679040#M205036</link>
    <description>&lt;P&gt;Lots of good suggestions however, if you have along list of variables, they might not fit in a single macro variable.&amp;nbsp; In that case I would suggest put the list in a dataset and use a call Execute construct to loop through the list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Untested code  */
data varlist;
  input binvar $;
cards;
var1
var2
var4
var6
var8
var9
;

data _null_;
  set varlist;
  call symput('binary',trim(binvar));
  call execute('
	  proc logistic data=work.dataset;
	    model outcome = &amp;amp;binary/ clodds=pl clparm=pl;
	    title "Model single binary variable against outcome";
		run;
  ');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 25 Aug 2020 03:02:20 GMT</pubDate>
    <dc:creator>ghosh</dc:creator>
    <dc:date>2020-08-25T03:02:20Z</dc:date>
    <item>
      <title>macro for looping through variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-looping-through-variables/m-p/678948#M205017</link>
      <description>&lt;P&gt;Hello everyone, I would like to write a bit of code to run a simple proc logistic for every binary variable I have in a data set. I have a %let statement where I have named all of my binary variables, but how would I go about looping through each variable and calling proc logistic?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my current code currently runs all binary variables at the same time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let binary = var1 var2 var4 var6 var8 var 1;

proc logistic data=work.dataset;
    model outcome = &amp;amp;binary/ clodds=pl clparm=pl;
    title "Model single binary variable against outcome";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Aug 2020 17:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-looping-through-variables/m-p/678948#M205017</guid>
      <dc:creator>magladde</dc:creator>
      <dc:date>2020-08-24T17:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: macro for looping through variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-looping-through-variables/m-p/678951#M205018</link>
      <description>&lt;P&gt;My recommended option:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option, very similar example except for PROC REG instead.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Skeleton example for you to modify your code:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/9603186" target="_blank"&gt;https://gist.github.com/statgeek/9603186&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/320585"&gt;@magladde&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone, I would like to write a bit of code to run a simple proc logistic for every binary variable I have in a data set. I have a %let statement where I have named all of my binary variables, but how would I go about looping through each variable and calling proc logistic?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my current code currently runs all binary variables at the same time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let binary = var1 var2 var4 var6 var8 var 1;

proc logistic data=work.dataset;
    model outcome = &amp;amp;binary/ clodds=pl clparm=pl;
    title "Model single binary variable against outcome";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 18:03:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-looping-through-variables/m-p/678951#M205018</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-08-24T18:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: macro for looping through variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-looping-through-variables/m-p/678979#M205024</link>
      <description>&lt;P&gt;A non-macro solution is given here, which probably runs faster than a macro solution&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 19:55:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-looping-through-variables/m-p/678979#M205024</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-24T19:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: macro for looping through variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-looping-through-variables/m-p/679040#M205036</link>
      <description>&lt;P&gt;Lots of good suggestions however, if you have along list of variables, they might not fit in a single macro variable.&amp;nbsp; In that case I would suggest put the list in a dataset and use a call Execute construct to loop through the list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Untested code  */
data varlist;
  input binvar $;
cards;
var1
var2
var4
var6
var8
var9
;

data _null_;
  set varlist;
  call symput('binary',trim(binvar));
  call execute('
	  proc logistic data=work.dataset;
	    model outcome = &amp;amp;binary/ clodds=pl clparm=pl;
	    title "Model single binary variable against outcome";
		run;
  ');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Aug 2020 03:02:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-looping-through-variables/m-p/679040#M205036</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2020-08-25T03:02:20Z</dc:date>
    </item>
  </channel>
</rss>

