<?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: Looping through table name in FROM in PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-table-name-in-FROM-in-PROC-SQL/m-p/523138#M142115</link>
    <description>'dynamically' as in a prompt?</description>
    <pubDate>Fri, 21 Dec 2018 18:49:14 GMT</pubDate>
    <dc:creator>tomrvincent</dc:creator>
    <dc:date>2018-12-21T18:49:14Z</dc:date>
    <item>
      <title>Looping through table name in FROM in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-table-name-in-FROM-in-PROC-SQL/m-p/523049#M142070</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my scenario, I need to change the table name used in PROC SQL dynamically(Highlighted in code) and use the same code for different names of table from database. I know for sure there are ways to do this (May be looping array) but instead of referring SAS documentation , I need any one of your help to provide me an glimpse of an idea about how can achieve this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in below sample, I&amp;nbsp; want to change the dataset name BKD1 and table name bkd(FROM statement) dynamically&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below code..&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table&lt;FONT color="#000000"&gt; dummy&lt;/FONT&gt;.&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;BKD1 &lt;/FONT&gt;&lt;/STRONG&gt;as select
count(case when CD= 'N' then 1  end) as Count_NewRecord,
count(case when CD= 'C' then 1  end) as COUNT_Changed,
count(case when CD= 'D' then 1  end) as Count_Duplicate
from layer&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.bkd&lt;/FONT&gt;&lt;/STRONG&gt; ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Dec 2018 13:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-table-name-in-FROM-in-PROC-SQL/m-p/523049#M142070</guid>
      <dc:creator>arunrami</dc:creator>
      <dc:date>2018-12-21T13:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through table name in FROM in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-table-name-in-FROM-in-PROC-SQL/m-p/523073#M142073</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/200330"&gt;@arunrami&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my scenario, I need to change the table name used in PROC SQL dynamically(Highlighted in code) and use the same code for different names of table from database. I know for sure there are ways to do this (May be looping array) but instead of referring SAS documentation , I need any one of your help to provide me an glimpse of an idea about how can achieve this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in below sample, I&amp;nbsp; want to change the dataset name BKD1 and table name bkd(FROM statement) dynamically&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Explain this whole thing further.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where are you getting the names of the other tables from? Show us. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What code are you referring to? Is it the variable CD?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Give us a clear example of what this means: "use the same code for different names of table from database".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Dec 2018 14:30:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-table-name-in-FROM-in-PROC-SQL/m-p/523073#M142073</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-12-21T14:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through table name in FROM in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-table-name-in-FROM-in-PROC-SQL/m-p/523075#M142075</link>
      <description>&lt;P&gt;Sounds like you are ready to begin learning how to use macro variables.&amp;nbsp; The SAS macro processor will examine your SAS statements and replace macro triggers with the code they generate and then pass that code onto SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you have this code you want to run.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table dummy.BKD1 as 
  select
    count(case when CD= 'N' then 1  end) as Count_NewRecord
   ,count(case when CD= 'C' then 1  end) as COUNT_Changed
   ,count(case when CD= 'D' then 1  end) as Count_Duplicate
 from layer.bkd 
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So first make a macro variable that has the value BKD.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let basename=bkd ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then replace the BKD in the code with references to the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let basename=bkd;
proc sql;
create table dummy.&amp;amp;basename.1 as 
  select
    count(case when CD= 'N' then 1  end) as Count_NewRecord
   ,count(case when CD= 'C' then 1  end) as COUNT_Changed
   ,count(case when CD= 'D' then 1  end) as Count_Duplicate
 from layer.&amp;amp;basename.
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Dec 2018 14:50:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-table-name-in-FROM-in-PROC-SQL/m-p/523075#M142075</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-21T14:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through table name in FROM in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-table-name-in-FROM-in-PROC-SQL/m-p/523138#M142115</link>
      <description>'dynamically' as in a prompt?</description>
      <pubDate>Fri, 21 Dec 2018 18:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-table-name-in-FROM-in-PROC-SQL/m-p/523138#M142115</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-12-21T18:49:14Z</dc:date>
    </item>
  </channel>
</rss>

