<?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: proc sql in a %Do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop/m-p/344150#M79062</link>
    <description>&lt;P&gt;You must have some reason to suspect that something is wrong. It would be helpful if you were to share that information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At any rate, here are a few things to look at.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code defines a macro but never tries to execute it. &amp;nbsp;You need to insert this line of code before the final DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%pull_data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DATA steps within the macro aren't really needed. &amp;nbsp;SQL can use your permanently saved SAS data sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;from raw.data&amp;amp;i&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is conceivable that your dates are actually datetime&amp;nbsp;values instead of date values, so the YEAR and QTR functions return the wrong values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is conceivable (SQL isn't my strongest area) that the GROUP BY clause needs to tell SQL that some fields are not to be found within the incoming data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;group by redcode, calculated year, calculated qtr;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Mar 2017 18:23:19 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-03-24T18:23:19Z</dc:date>
    <item>
      <title>proc sql in a %Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop/m-p/344136#M79057</link>
      <description>&lt;P&gt;I am trying to pull data from 17 datasets, data2001, data2002, ...data2017 (one for each year from 2001 to 2017). I also need to run a proc sql procedure to each dataset. Can anyone tell me what is wrong with my code please? Many thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro pull_data;&lt;BR /&gt;%do i = 2001 %to 2017;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; data tmp&amp;amp;i;&lt;BR /&gt;&amp;nbsp; set raw.data&amp;amp;i;&lt;BR /&gt;&amp;nbsp; run;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table temp&amp;amp;i as&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select unique&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; redcode, year(date) as year, qtr(date) as qtr, mean(price) as avr_price, count(price) as n&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from tmp&amp;amp;i&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by redcode, year, qtr;&lt;BR /&gt;&amp;nbsp; quit;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;%mend pull_data;&lt;BR /&gt;&lt;BR /&gt;data full; set temp2001 - temp2017; run;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 17:37:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop/m-p/344136#M79057</guid>
      <dc:creator>dyxdyx</dc:creator>
      <dc:date>2017-03-24T17:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop/m-p/344150#M79062</link>
      <description>&lt;P&gt;You must have some reason to suspect that something is wrong. It would be helpful if you were to share that information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At any rate, here are a few things to look at.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code defines a macro but never tries to execute it. &amp;nbsp;You need to insert this line of code before the final DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%pull_data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DATA steps within the macro aren't really needed. &amp;nbsp;SQL can use your permanently saved SAS data sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;from raw.data&amp;amp;i&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is conceivable that your dates are actually datetime&amp;nbsp;values instead of date values, so the YEAR and QTR functions return the wrong values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is conceivable (SQL isn't my strongest area) that the GROUP BY clause needs to tell SQL that some fields are not to be found within the incoming data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;group by redcode, calculated year, calculated qtr;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 18:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop/m-p/344150#M79062</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-24T18:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop/m-p/344156#M79064</link>
      <description>&lt;P&gt;Astouding, thanks so much for the quick reply. You are spot on - I did not have the %pull_data line. Once I add it to the code, it seems to be working now. Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 18:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop/m-p/344156#M79064</guid>
      <dc:creator>dyxdyx</dc:creator>
      <dc:date>2017-03-24T18:31:52Z</dc:date>
    </item>
  </channel>
</rss>

