<?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 Why do macros not work in loops of iml? in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592079#M4843</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
do k=1 to 5;
 call symputx('kk',k);
 j=k+1;
 s=J(1,2,0);
 s[1]=k;
 s[2]=j;
 create s&amp;amp;kk. from s;
 append from s;
 close s&amp;amp;kk.;
end;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is one example, and it seems that call symputx does not work in loops?&lt;/P&gt;</description>
    <pubDate>Fri, 27 Sep 2019 04:14:50 GMT</pubDate>
    <dc:creator>supmilk</dc:creator>
    <dc:date>2019-09-27T04:14:50Z</dc:date>
    <item>
      <title>Why do macros not work in loops of iml?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592079#M4843</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
do k=1 to 5;
 call symputx('kk',k);
 j=k+1;
 s=J(1,2,0);
 s[1]=k;
 s[2]=j;
 create s&amp;amp;kk. from s;
 append from s;
 close s&amp;amp;kk.;
end;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is one example, and it seems that call symputx does not work in loops?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2019 04:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592079#M4843</guid>
      <dc:creator>supmilk</dc:creator>
      <dc:date>2019-09-27T04:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: Why do macros not work in loops of iml?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592080#M4844</link>
      <description>General rule of thumb is you can't use a macro variable in the same step as you create it due to timing issues. There are some ways to get around that using SYMGET but I'm not sure how that works in IML. You'd get similar behaviour in a data step. &lt;BR /&gt;</description>
      <pubDate>Fri, 27 Sep 2019 04:20:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592080#M4844</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-27T04:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: Why do macros not work in loops of iml?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592095#M4845</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro a();
proc iml;
%do k=1 %to 5;
 k=%sysevalf(&amp;amp;k);
 call symputx('kk',k);
 j=k+1;
 s=J(1,2,0);
 s[1]=k;
 s[2]=j;
 create s&amp;amp;kk. from s;
 append from s;
%end;
quit;
%mend;

%a();&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I find that it works when I put iml into a macro, but I still do not know why?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2019 06:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592095#M4845</guid>
      <dc:creator>supmilk</dc:creator>
      <dc:date>2019-09-27T06:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: Why do macros not work in loops of iml?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592110#M4846</link>
      <description>&lt;P&gt;As a general rule, you will almost never need to&amp;nbsp;mix macros&amp;nbsp;within IML, as a pure IML solution will exist.&amp;nbsp; For example you can use an IML loop instead of the macro loop, making&amp;nbsp;data set names on the fly using string concatenation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
do k=1 to 5;
 j=k+1;
 s=J(1,2,0);
 s[1]=k;
 s[2]=j;
 create (cats('s',char(k))) from s;
 append from s;
end;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Sep 2019 09:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592110#M4846</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2019-09-27T09:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Why do macros not work in loops of iml?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592115#M4847</link>
      <description>&lt;P&gt;See the article &lt;A href="https://blogs.sas.com/content/iml/2013/06/19/macros-and-loops.html" target="_self"&gt;"Macros and loops in the SAS/IML language,"&lt;/A&gt; which explains why your program doesn't work the way you expected it to.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2019 10:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592115#M4847</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-09-27T10:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: Why do macros not work in loops of iml?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592385#M4848</link>
      <description>&lt;P&gt;thank you for your reply, and one more question:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro stat(s_t);

proc iml;

%do kk=1 %to %sysevalf(&amp;amp;s_t);

kk=%sysevalf(&amp;amp;kk);

%end;

quit;

%put &amp;amp;kk.;

%mend;

%stat(6);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;when I put iml program into a macro, the mixed program works, but %put result goes to 7. I can't find the answer from the blog "macros and loops in the SAS/IML language".&lt;/P&gt;</description>
      <pubDate>Sat, 28 Sep 2019 12:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592385#M4848</guid>
      <dc:creator>supmilk</dc:creator>
      <dc:date>2019-09-28T12:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Why do macros not work in loops of iml?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592406#M4849</link>
      <description>&lt;P&gt;This is how an iterative macro do loop normally operates.&amp;nbsp; The documentation states "the value of &lt;SPAN class="xis-userSuppliedValue"&gt;macro-variable&lt;/SPAN&gt; changes by the value of &lt;SPAN class="xis-userSuppliedValue"&gt;increment&lt;/SPAN&gt; until the value of &lt;SPAN class="xis-userSuppliedValue"&gt;macro-variable&lt;/SPAN&gt; is outside the range of integers included by &lt;SPAN class="xis-userSuppliedValue"&gt;start&lt;/SPAN&gt; and &lt;SPAN class="xis-userSuppliedValue"&gt;stop".&amp;nbsp;&amp;nbsp; So with a default increment of 1, the loop macro variable will be one more than than stop after the loop.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Sep 2019 16:01:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592406#M4849</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2019-09-28T16:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Why do macros not work in loops of iml?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592410#M4850</link>
      <description>&lt;P&gt;Thanks a lot for your help!&lt;/P&gt;</description>
      <pubDate>Sat, 28 Sep 2019 17:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592410#M4850</guid>
      <dc:creator>supmilk</dc:creator>
      <dc:date>2019-09-28T17:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: Why do macros not work in loops of iml?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592471#M4851</link>
      <description>&lt;P&gt;And Ian's answer not only app[lies to macro loops but to te standard DO loop as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
do i = 1 to 6;
end;
put i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In fact, this behavior is not unique to SAS. It is the same in all programming languages that I have ever seen.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Sep 2019 10:08:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/592471#M4851</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-09-29T10:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: Why do macros not work in loops of iml?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/595356#M4852</link>
      <description>&lt;P&gt;Do you still have questions? If not, please mark a response as the answer.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 12:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Why-do-macros-not-work-in-loops-of-iml/m-p/595356#M4852</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-10-10T12:39:58Z</dc:date>
    </item>
  </channel>
</rss>

