<?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 looping in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-looping/m-p/21954#M3554</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are mixing up macro logic and data step logic. The reason that the %PUT is getting an error is that it is compiled BEFORE the data step runs.&amp;nbsp; So the CALL SYMPUT function has not been called yet.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a macro use the %LET statement to assign a value to a macro variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;P&gt;%macro doit(m,n);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do i=&amp;amp;m %to &amp;amp;n;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let st&amp;amp;i=%eval(&amp;amp;i+1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend doit;&lt;/P&gt;&lt;P&gt;%doit(1,2);&lt;/P&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a data step use the DO statement to loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;P&gt;%let m=1;&lt;/P&gt;&lt;P&gt;%let n=2;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=&amp;amp;m to &amp;amp;n;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symputx(cats('ST',i),i+1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS: Do not use DO as the name of a macro as %DO is already a macro statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 02 Oct 2011 17:22:19 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2011-10-02T17:22:19Z</dc:date>
    <item>
      <title>macro looping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-looping/m-p/21952#M3552</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In th below code as you can see im trying to create a macro variable for each iteration of 'i' but when i try to print them onto saslog im getting the error&lt;/P&gt;&lt;P&gt;as Apparent symbolic reference ST1not resolved .&lt;/P&gt;&lt;P&gt;Any help would be appreciated!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro do(m,n);&lt;/P&gt;&lt;P&gt;%let i=;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;%do i=&amp;amp;m %to &amp;amp;n;&lt;/P&gt;&lt;P&gt;&amp;nbsp; st=%eval(&amp;amp;i+1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; call symput("st&amp;amp;i",st);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %put &amp;amp;&amp;amp;st&amp;amp;i;&lt;/P&gt;&lt;P&gt; %end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do(1,2)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Oct 2011 16:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-looping/m-p/21952#M3552</guid>
      <dc:creator>newbie</dc:creator>
      <dc:date>2011-10-02T16:47:40Z</dc:date>
    </item>
    <item>
      <title>macro looping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-looping/m-p/21953#M3553</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P class="jive-rendered-content" style="font-size: 13px; margin-bottom: 20px; overflow-x: visible; overflow-y: visible; position: relative; width: 506px; padding: 2px;"&gt; I can't test your code at the moment, but I doubt if it will work for a couple of reasons: (1) I think %do is a reserved word and (2) the macro variable won't resolve within the same datastep it is created.&amp;nbsp; Try something like the following:&lt;/P&gt;&lt;P&gt;%macro doit(m,n);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do i=&amp;amp;m %to &amp;amp;n;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; st=%eval(&amp;amp;i+1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symput("st&amp;amp;i",st);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;&amp;amp;st&amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%doit(1,2)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="jive-thread-post-details clearfix" id="discussion-action-div-baseDiscussionForm"&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN class="acclaim-container" id="acclaim-container-2-106533-" style="font-size: 12px; display: inline; position: relative;"&gt;&lt;DIV class="acclaim-like-container" id="jive-acclaim-like-container-2-106533-" style="font-size: 12px; display: inline; position: relative;"&gt;&lt;A _jive_internal="true" class=" jive-acclaim-likelink" href="https://communities.sas.com/message/106533#" id="jive-acclaim-likelink-2-106533-" style="font-size: 12px; color: #0e66ba; display: inline-block;"&gt;macro looping&lt;/A&gt;&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Oct 2011 17:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-looping/m-p/21953#M3553</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-10-02T17:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: macro looping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-looping/m-p/21954#M3554</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are mixing up macro logic and data step logic. The reason that the %PUT is getting an error is that it is compiled BEFORE the data step runs.&amp;nbsp; So the CALL SYMPUT function has not been called yet.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a macro use the %LET statement to assign a value to a macro variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;P&gt;%macro doit(m,n);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do i=&amp;amp;m %to &amp;amp;n;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let st&amp;amp;i=%eval(&amp;amp;i+1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend doit;&lt;/P&gt;&lt;P&gt;%doit(1,2);&lt;/P&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a data step use the DO statement to loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;P&gt;%let m=1;&lt;/P&gt;&lt;P&gt;%let n=2;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=&amp;amp;m to &amp;amp;n;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symputx(cats('ST',i),i+1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS: Do not use DO as the name of a macro as %DO is already a macro statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Oct 2011 17:22:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-looping/m-p/21954#M3554</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-10-02T17:22:19Z</dc:date>
    </item>
  </channel>
</rss>

