<?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 Loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop/m-p/231382#M308299</link>
    <description>&lt;P&gt;You're right, it won't work. &amp;nbsp;Here's the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider this statement before the loop begins:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let CP_ID = %scan(&amp;amp;CPI_ID, &amp;amp;i);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before this statement, &amp;amp;CP_ID contained two words. &amp;nbsp;After the statement, it only contains one word. &amp;nbsp;So inside the %do %until loop, when you increment &amp;amp;i to 2, there is no longer a second word for %SCAN to locate within &amp;amp;CP_ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solution is simple ... don't replace the two-word version of &amp;amp;CP_ID. &amp;nbsp;Assign each word to a new macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
    <pubDate>Fri, 23 Oct 2015 16:10:23 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2015-10-23T16:10:23Z</dc:date>
    <item>
      <title>Macro Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop/m-p/231377#M308297</link>
      <description>&lt;P&gt;Hey all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a macro that&amp;nbsp;I want to loop through a couple of variables (&amp;amp;CP_ID and &amp;amp;REP) and pass them to the program.&amp;nbsp; It works fine for the 1st iteration but never starts the 2nd etc...&amp;nbsp; What is my code missing?&amp;nbsp; Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;BR /&gt;&amp;nbsp;select &amp;nbsp;CP_ID, REP into :CP_ID separated by ' ', :REP separated by ' ' &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;from crep2.crep_attributes;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro crep_rs;&lt;BR /&gt;&amp;nbsp;%let i = 1;&lt;BR /&gt;&amp;nbsp;%let YrMo = &amp;amp;YrMo;&lt;BR /&gt;&amp;nbsp;%let CP_ID = %scan(&amp;amp;CP_ID, &amp;amp;i);&lt;BR /&gt;&amp;nbsp;%let REP = %scan(&amp;amp;REP, &amp;amp;i);&lt;BR /&gt;&amp;nbsp;%do %until (&amp;amp;CP_ID=);&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;A BUNCH OF VALID SAS CODE&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;%let i = %eval(&amp;amp;i+1);&lt;BR /&gt;&amp;nbsp;%let CP_ID = %scan(&amp;amp;CP_ID,&amp;amp;i);&lt;BR /&gt;&amp;nbsp;%let REP = %scan(&amp;amp;REP,&amp;amp;i);&lt;BR /&gt;&amp;nbsp;%end;&lt;BR /&gt;&amp;nbsp;%mend; &lt;BR /&gt;%crep_rs;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 16:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop/m-p/231377#M308297</guid>
      <dc:creator>BU2B</dc:creator>
      <dc:date>2015-10-23T16:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop/m-p/231379#M308298</link>
      <description>&lt;P&gt;You are changing values for &amp;amp;CP_ID and &amp;amp;REP in the macro with statements:&lt;/P&gt;
&lt;P&gt;%let CP_ID = %scan(&amp;amp;CP_ID, &amp;amp;i);&lt;BR /&gt; %let REP = %scan(&amp;amp;REP, &amp;amp;i);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;create new&amp;nbsp;macro variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let _CP_ID = %scan(&amp;amp;CP_ID, &amp;amp;i);&lt;BR /&gt; %let _REP = %scan(&amp;amp;REP, &amp;amp;i);&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;don't forget to change references eleswhere within the code.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 16:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop/m-p/231379#M308298</guid>
      <dc:creator>ndp</dc:creator>
      <dc:date>2015-10-23T16:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop/m-p/231382#M308299</link>
      <description>&lt;P&gt;You're right, it won't work. &amp;nbsp;Here's the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider this statement before the loop begins:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let CP_ID = %scan(&amp;amp;CPI_ID, &amp;amp;i);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before this statement, &amp;amp;CP_ID contained two words. &amp;nbsp;After the statement, it only contains one word. &amp;nbsp;So inside the %do %until loop, when you increment &amp;amp;i to 2, there is no longer a second word for %SCAN to locate within &amp;amp;CP_ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solution is simple ... don't replace the two-word version of &amp;amp;CP_ID. &amp;nbsp;Assign each word to a new macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 16:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop/m-p/231382#M308299</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-23T16:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop/m-p/231422#M308300</link>
      <description>&lt;P&gt;Thanks guys!&amp;nbsp; I really apreciate it.&amp;nbsp; have a good weekend...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 18:13:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop/m-p/231422#M308300</guid>
      <dc:creator>BU2B</dc:creator>
      <dc:date>2015-10-23T18:13:41Z</dc:date>
    </item>
  </channel>
</rss>

