<?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: Sas macro loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511885#M137782</link>
    <description>Probably wants to use &amp;amp;I instead of &amp;amp;NID so that each time through the loop is different instead of repeating the same code &amp;amp;NID times.&lt;BR /&gt;</description>
    <pubDate>Fri, 09 Nov 2018 23:42:10 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-11-09T23:42:10Z</dc:date>
    <item>
      <title>Sas macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511808#M137748</link>
      <description>&lt;P&gt;I am getting an error due to the fact that the&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;one variable is not working &amp;amp;ID&amp;amp;nID&lt;/P&gt;
&lt;P&gt;what am I doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;ID1;&lt;BR /&gt;810034882&lt;BR /&gt;33 %put &amp;amp;ID2;&lt;BR /&gt;810182482&lt;BR /&gt;34 %put &amp;amp;ID3;&lt;BR /&gt;810724412&lt;BR /&gt;35 %put &amp;amp;ID1;&lt;BR /&gt;810034882&lt;BR /&gt;36 %put &amp;amp;nID;&lt;BR /&gt;3&lt;BR /&gt;37 &lt;BR /&gt;38 %macro loop;&lt;BR /&gt;39 &lt;BR /&gt;40 %do i= 1 %to &amp;amp;nID;&lt;BR /&gt;41 &lt;BR /&gt;42 &lt;BR /&gt;43 Proc sql;&lt;BR /&gt;44 create table bs_company_&amp;amp;ID&amp;amp;NID as&lt;BR /&gt;45 select distinct &amp;amp;ID&amp;amp;NID as orgnbr&lt;BR /&gt;46 ,t0.c&lt;BR /&gt;47 ,t0.c1&lt;BR /&gt;48 ,t0.c2&lt;BR /&gt;49&amp;nbsp;&lt;BR /&gt;50 ,&amp;nbsp;t1.x&lt;BR /&gt;51 ,t1.xxx&lt;/P&gt;
&lt;P&gt;52 ,t1.xxxx&lt;BR /&gt;53 ,t0.xxx1&lt;BR /&gt;54 ,t0.xxx2&lt;BR /&gt;55 ,t0.xxx3&lt;BR /&gt;56 ,t0.xxx4&lt;BR /&gt;57 ,t0.xxx5&lt;BR /&gt;58 &lt;BR /&gt;59 from bs_pre_company as t0&lt;BR /&gt;60 left join s18_19.startfile2 as t1&lt;BR /&gt;61 on &amp;amp;ID&amp;amp;NID=t1.orgnbr&lt;BR /&gt;62&lt;BR /&gt;63&amp;nbsp; &lt;BR /&gt;64&amp;nbsp; &lt;BR /&gt;65&amp;nbsp; &lt;BR /&gt;66 &lt;BR /&gt;67 ;&lt;BR /&gt;68 quit;&lt;BR /&gt;69 &lt;BR /&gt;70 &lt;BR /&gt;71 %END;&lt;BR /&gt;72 %MEND LOOP;&lt;BR /&gt;73 %LOOP;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;WARNING: Apparent symbolic reference ID not resolved.&lt;BR /&gt;NOTE: Line generated by the invoked macro "LOOP".&lt;BR /&gt;73 &amp;amp;ID&amp;amp;NID as select distinct&lt;BR /&gt; _&lt;BR /&gt; 22&lt;BR /&gt; 200&lt;BR /&gt;WARNING: Apparent symbolic reference ID not resolved.&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: (, '.', AS, LIKE.&lt;/P&gt;
&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;NOTE: Line generated by the invoked macro "LOOP".&lt;BR /&gt;73 &amp;amp;ID&amp;amp;NID as organisationregistrationnbr&lt;BR /&gt; _&lt;BR /&gt; 22&lt;BR /&gt;73 ! ,t0.company_customer_id ,t0.SourceSystId as Company_sourcesystid ,t0.contractnbr as company_contractnbr&lt;BR /&gt;73 ! ,input(put&lt;BR /&gt;WARNING: Apparent symbolic reference ID not resolved.&lt;BR /&gt;NOTE: Line generated by the invoked macro "LOOP".&lt;BR /&gt;73 &amp;amp;ID&amp;amp;NID=t1.organisationregistrationnbr where&lt;/P&gt;
&lt;P&gt;_&lt;/P&gt;
&lt;P&gt;22&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, &lt;BR /&gt; a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER.&lt;/P&gt;
&lt;P&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt; real time 0.00 seconds&lt;BR /&gt; cpu time 0.01 seconds&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2018 19:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511808#M137748</guid>
      <dc:creator>Kiteulf</dc:creator>
      <dc:date>2018-11-09T19:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sas macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511812#M137749</link>
      <description>Try &amp;amp;ID.&amp;amp;NID. -&amp;gt; you need the periods to tell SAS where the macro variable ends.</description>
      <pubDate>Fri, 09 Nov 2018 19:54:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511812#M137749</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-09T19:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: Sas macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511813#M137750</link>
      <description>&lt;P&gt;First off,&lt;/P&gt;
&lt;P&gt;are you expecting -&amp;gt;&lt;SPAN&gt;&amp;nbsp;select distinct &lt;STRONG&gt;&amp;amp;ID&amp;amp;NID&lt;/STRONG&gt;&amp;nbsp; to resolve in a column name that is all numbers?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2018 20:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511813#M137750</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-09T20:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Sas macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511823#M137753</link>
      <description>&lt;P&gt;To help us understand your log post it into a code box opened using the forum's {I} icon to preserve error message formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second to help yourself debug macro errors use OPTIONS MPRINT; to show the entire text generated by your macro code.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2018 20:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511823#M137753</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-09T20:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: Sas macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511868#M137771</link>
      <description>&lt;P&gt;I think you are trying to get the value of the macro variables ID1, ID2, etc.&amp;nbsp; Instead what you asked for is the value of the macro variable ID, which SAS is saying doesn't exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to use multiple &amp;amp;'s.&amp;nbsp; When the macro processor sees two &amp;amp; it changes it into one a then re-processes the string to see if there are more macro references.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let id1=SAM;
%let i=1;
%put ID&amp;amp;i = &amp;amp;&amp;amp;id&amp;amp;i ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or this loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i= 1 %to &amp;amp;nID;
  %put ID&amp;amp;i = &amp;amp;&amp;amp;id&amp;amp;i ;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2018 22:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511868#M137771</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-09T22:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Sas macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511884#M137781</link>
      <description>&lt;P&gt;I think&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;has identified the right issue here.&amp;nbsp; To put it in the context of your program, this section tries to find &amp;amp;ID (which does not exist):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;select distinct &amp;amp;ID&amp;amp;NID as orgnbr&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Instead, use:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;select distinct &amp;amp;&amp;amp;ID&amp;amp;NID as orgnbr&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2018 23:39:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511884#M137781</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-11-09T23:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: Sas macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511885#M137782</link>
      <description>Probably wants to use &amp;amp;I instead of &amp;amp;NID so that each time through the loop is different instead of repeating the same code &amp;amp;NID times.&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Nov 2018 23:42:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-macro-loop/m-p/511885#M137782</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-09T23:42:10Z</dc:date>
    </item>
  </channel>
</rss>

