<?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: Macros and looping into Sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macros-and-looping-into-Sql/m-p/723378#M224464</link>
    <description>&lt;P&gt;Whenever you want to take code a step further, &lt;STRONG&gt;FIRST&lt;/STRONG&gt; make sure that the current iteration works.&lt;/P&gt;
&lt;P&gt;Your current code won't work, as the dataset OUTPUT will contain the results of the &lt;STRONG&gt;last&lt;/STRONG&gt; %DO loop only. All previous results will be lost.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the correct syntax of SQL Server, I suggest you study the relevant Microsoft documentation, and have a talk with your SQL Server admins about the names of your tables there.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Mar 2021 07:55:35 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-03-04T07:55:35Z</dc:date>
    <item>
      <title>Macros and looping into Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros-and-looping-into-Sql/m-p/723372#M224462</link>
      <description>&lt;P&gt;I'm seeking for some help to convert the below macro program to proc SQL without any macros and Loop. Because I want to use this query in explicit pass through&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/* Simple macro to print out the values of the macro variables created in step above */
%macro check() ;
     %do i=1 %to &amp;amp;tableCnt ;
          %put table&amp;amp;i = &amp;amp;&amp;amp;table&amp;amp;i;
Proc sql;
create table output as select t1.*,t2.reportingdate
from &amp;amp;&amp;amp;table&amp;amp;i t1 inner join 
Meta t2
on (t1.ID=t2.ID)
;
quit; 
     %end ;

%mend ;

/* Call check macro */
%check ;&lt;/PRE&gt;
&lt;P&gt;Excepted code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
           connect to SQLSVR (DATAsrc=&amp;amp;DATASRC. AUTHDOMAIN="&amp;amp;AUTHDOMAIN.");
Create table meta as SELECT * 
          FROM  CONNECTION TO SQLSVR 
                ( 
              &amp;lt;Query to be used once converting the macro program to sql&amp;gt;
                )
                
          ;           disconnect from SQLSVR;
quit;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Mar 2021 06:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros-and-looping-into-Sql/m-p/723372#M224462</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-03-04T06:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macros and looping into Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros-and-looping-into-Sql/m-p/723378#M224464</link>
      <description>&lt;P&gt;Whenever you want to take code a step further, &lt;STRONG&gt;FIRST&lt;/STRONG&gt; make sure that the current iteration works.&lt;/P&gt;
&lt;P&gt;Your current code won't work, as the dataset OUTPUT will contain the results of the &lt;STRONG&gt;last&lt;/STRONG&gt; %DO loop only. All previous results will be lost.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the correct syntax of SQL Server, I suggest you study the relevant Microsoft documentation, and have a talk with your SQL Server admins about the names of your tables there.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 07:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros-and-looping-into-Sql/m-p/723378#M224464</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-04T07:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: Macros and looping into Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros-and-looping-into-Sql/m-p/723379#M224465</link>
      <description>&lt;P&gt;PS you do not have to convert the &lt;EM&gt;macro&lt;/EM&gt;, you have to convert the &lt;EM&gt;SQL code&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 07:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros-and-looping-into-Sql/m-p/723379#M224465</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-04T07:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macros and looping into Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros-and-looping-into-Sql/m-p/723400#M224475</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might find that you can use macro code to loop through all of the tables with the pass through SQL as the macro code is resolved first to generate the text (SQL code). You'll still need to address issues, as highlighted by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 10:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros-and-looping-into-Sql/m-p/723400#M224475</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2021-03-04T10:30:59Z</dc:date>
    </item>
  </channel>
</rss>

