<?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: Loop through code changing table name each time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467479#M285358</link>
    <description>&lt;P&gt;a quick look tells me this is some typo here before even looking further&lt;/P&gt;&lt;P&gt;%do index = 1 % to 12;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;should be&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do index = 1 &lt;STRONG&gt;%to&lt;/STRONG&gt; 12;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Jun 2018 17:32:14 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-06-04T17:32:14Z</dc:date>
    <item>
      <title>Loop through code changing table name each time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467477#M285357</link>
      <description>&lt;P&gt;Good afternoon experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; I have very limited experience with loops and am attempting to adapt a working code but am not having any luck. I have a list of table names in a macro (&amp;amp;table_names). I want to loop through a piece&amp;nbsp;of code for each table listed in the macro. The table names don't always exist (they differ because tables are based on reference periods and some times a table is not created for each reference period).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There will never be more than 12 table names (corresponding to months in a year).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code itself is gathering data from the SIR library for each table in the &amp;amp;table_names macro (if the table exists) based on ID's in a previously generated table and naming the table incrementally (&amp;amp;index) as it creates each new table (current_table_1, current_table_2 etc.).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro run_macro;
%do index = 1 % to 12;

proc sql;
create table current_table_&amp;amp;index as
select *
from sir.&amp;amp;&amp;amp;table_names&amp;amp;index a where exists
(select * 
from work.previous_table b
where ID = ID);
quit;

%end;
%mend;
%run_macro;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm not getting anything when I run the code. I'm not sure where I'm going wrong.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have any suggestions, I would be so grateful for your help! I would be happy to add additional information. Please let me know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2018 17:26:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467477#M285357</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2018-06-04T17:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through code changing table name each time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467479#M285358</link>
      <description>&lt;P&gt;a quick look tells me this is some typo here before even looking further&lt;/P&gt;&lt;P&gt;%do index = 1 % to 12;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;should be&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do index = 1 &lt;STRONG&gt;%to&lt;/STRONG&gt; 12;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2018 17:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467479#M285358</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-04T17:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through code changing table name each time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467480#M285359</link>
      <description>My bad. I typo'd in my question, but the actual code is %to. Thanks for your suggestion!</description>
      <pubDate>Mon, 04 Jun 2018 17:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467480#M285359</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2018-06-04T17:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through code changing table name each time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467481#M285360</link>
      <description>&lt;P&gt;Ok good. Please post your log to the community for anybody to examine further. Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2018 17:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467481#M285360</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-04T17:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through code changing table name each time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467482#M285361</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I have a list of table names in a macro (&amp;amp;table_names)&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Actually, this is a macro variable, not a macro. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Since it is a list of names, you cannot use a construct like&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;table_names&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;index&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because when &amp;amp;index=1, this resolves to &amp;amp;table_names1, and that doesn't exist, you only have &amp;amp;table_names.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you might want to try replacing the line in your code with &amp;amp;&amp;amp;table_names&amp;amp;index with this line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; sir&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;%scan(&amp;amp;table_names,&amp;amp;index,%str( ))&lt;/SPAN&gt; a &lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;ex&lt;/SPAN&gt;ists&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and this should work because it is finding the words in &amp;amp;table_names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I'm not getting anything when I run the code. I'm not sure where I'm going wrong.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From now on, when you have an error, we need to see the SASLOG as well as the SAS code. If it involves a macro, you need to turn on OPTIONS MPRINT; before you run the macro.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2018 17:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467482#M285361</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-04T17:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through code changing table name each time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467483#M285362</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe this example is helpful?&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n1qvxz5u3uru7yn1nk7q64ohvwak.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n1qvxz5u3uru7yn1nk7q64ohvwak.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2018 17:43:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467483#M285362</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-04T17:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through code changing table name each time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467486#M285363</link>
      <description>That did it! Thanks so much Paige! You totally saved me. Thank you also for your explanations. I learned something new today thanks to you.</description>
      <pubDate>Mon, 04 Jun 2018 17:54:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467486#M285363</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2018-06-04T17:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through code changing table name each time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467487#M285364</link>
      <description>Thanks for the link Reeza. This helps me understand a bit more of what I'm running. I appreciate the link.</description>
      <pubDate>Mon, 04 Jun 2018 17:55:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467487#M285364</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2018-06-04T17:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through code changing table name each time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467521#M285365</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/75160"&gt;@sas-inquirer&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just for giggles could you mention what your SIR library is used for? I have an annual project where I use SIR for a &lt;STRONG&gt;S&lt;/STRONG&gt;chool &lt;STRONG&gt;I&lt;/STRONG&gt;mmunization &lt;STRONG&gt;R&lt;/STRONG&gt;eport and just curious about if the usage is at all similar.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2018 21:04:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467521#M285365</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-06-04T21:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through code changing table name each time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467541#M285366</link>
      <description>It’s a business register library. No connection. Not sure what it stands for though.</description>
      <pubDate>Mon, 04 Jun 2018 23:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-code-changing-table-name-each-time/m-p/467541#M285366</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2018-06-04T23:16:44Z</dc:date>
    </item>
  </channel>
</rss>

