<?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 Problem using PROC SQL within a Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-using-PROC-SQL-within-a-Macro/m-p/135841#M27559</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code looks similar to this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Macro CFT(PGM,ID);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; CREATE TABLE work.tempRV AS&lt;/P&gt;&lt;P&gt;&amp;nbsp; SELECT DISTINCT RV&lt;/P&gt;&lt;P&gt;&amp;nbsp; from work.SPECS a&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHERE a.Revision = &amp;amp;ID.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SELECT cats(count(*))&lt;/P&gt;&lt;P&gt;&amp;nbsp; into :MAXRV&lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM work.tempRV;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select DISTINCT RV&lt;/P&gt;&lt;P&gt;&amp;nbsp; into :RV1-:RV&amp;amp;MAXRV.&lt;/P&gt;&lt;P&gt;&amp;nbsp; from work.tempRV;&lt;/P&gt;&lt;P&gt;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When the macro is called, the first PROC SQL runs as expected but the second and third do not execute.&amp;nbsp; Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 10 Jun 2014 14:17:25 GMT</pubDate>
    <dc:creator>GA_Mike</dc:creator>
    <dc:date>2014-06-10T14:17:25Z</dc:date>
    <item>
      <title>Problem using PROC SQL within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-using-PROC-SQL-within-a-Macro/m-p/135841#M27559</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code looks similar to this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Macro CFT(PGM,ID);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; CREATE TABLE work.tempRV AS&lt;/P&gt;&lt;P&gt;&amp;nbsp; SELECT DISTINCT RV&lt;/P&gt;&lt;P&gt;&amp;nbsp; from work.SPECS a&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHERE a.Revision = &amp;amp;ID.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SELECT cats(count(*))&lt;/P&gt;&lt;P&gt;&amp;nbsp; into :MAXRV&lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM work.tempRV;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select DISTINCT RV&lt;/P&gt;&lt;P&gt;&amp;nbsp; into :RV1-:RV&amp;amp;MAXRV.&lt;/P&gt;&lt;P&gt;&amp;nbsp; from work.tempRV;&lt;/P&gt;&lt;P&gt;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When the macro is called, the first PROC SQL runs as expected but the second and third do not execute.&amp;nbsp; Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Jun 2014 14:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-using-PROC-SQL-within-a-Macro/m-p/135841#M27559</guid>
      <dc:creator>GA_Mike</dc:creator>
      <dc:date>2014-06-10T14:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using PROC SQL within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-using-PROC-SQL-within-a-Macro/m-p/135842#M27560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do the steps run if you do not use macro code? Does work.tempRV actually have any records?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do question why use the cats(count(*)) structure as it shouldn't be any different than count(*).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And if the code is similar it isn't identical so we may not be much help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Jun 2014 14:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-using-PROC-SQL-within-a-Macro/m-p/135842#M27560</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-06-10T14:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using PROC SQL within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-using-PROC-SQL-within-a-Macro/m-p/135843#M27561</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have a scope problem, I'm guessing. The macro variables are created in the process but are not available afterwards.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Macro CFT(ID=);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; PROC SQL;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; CREATE TABLE work.tempRV AS&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SELECT DISTINCT name&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; from sashelp.class a&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHERE sex = "&amp;amp;ID.";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SELECT cats(count(*))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; into :MAXRV&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM work.tempRV;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc sql;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select DISTINCT name&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; into :RV1-:RV&amp;amp;MAXRV.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; from work.tempRV;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; %put &amp;amp;rv1.;&lt;/P&gt;&lt;P&gt; %put &amp;amp;maxrv;&lt;/P&gt;&lt;P&gt; %put &amp;amp;&amp;amp;&amp;amp;rv&amp;amp;maxrv.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%cft(ID=F);&lt;/P&gt;&lt;P&gt; %put &amp;amp;rv1.;&lt;/P&gt;&lt;P&gt; %put &amp;amp;maxrv;&lt;/P&gt;&lt;P&gt; %put &amp;amp;&amp;amp;&amp;amp;rv&amp;amp;maxrv.;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Jun 2014 14:46:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-using-PROC-SQL-within-a-Macro/m-p/135843#M27561</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-06-10T14:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using PROC SQL within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-using-PROC-SQL-within-a-Macro/m-p/135844#M27562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;They do run if they are outside of the macro.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;work.tempRV does contain records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can't remember why I switched from count(*) to cats(count(*)). There was something in the data that was causing an issue and that is how I resolved it.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By similar what I mean is that I changed the permanent library names to 'work' just to try to avoid confusion.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Jun 2014 14:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-using-PROC-SQL-within-a-Macro/m-p/135844#M27562</guid>
      <dc:creator>GA_Mike</dc:creator>
      <dc:date>2014-06-10T14:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using PROC SQL within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-using-PROC-SQL-within-a-Macro/m-p/135845#M27563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok.&amp;nbsp; I found the reason for cats(count(*)) in my notes.&amp;nbsp; If I only used count(*) in the third PROC SQL the definition of the macro variable RV errors due to leading spaces.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sql;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; select DISTINCT RV&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; into :RV1-:RV&amp;amp;MAXRV.&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;-- So right here instead of resolving to&amp;nbsp;&amp;nbsp; into :RV1-:RV10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; it does this&amp;nbsp; into :RV1-:RV&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp; and errors.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; from work.tempRV;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Jun 2014 15:27:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-using-PROC-SQL-within-a-Macro/m-p/135845#M27563</guid>
      <dc:creator>GA_Mike</dc:creator>
      <dc:date>2014-06-10T15:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using PROC SQL within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-using-PROC-SQL-within-a-Macro/m-p/135846#M27564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Reeza has the right idea here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL runs every time (with complications if the incoming data set happens to be empty).&amp;nbsp; It creates your macro variables.&amp;nbsp; However, it always creates them in the LOCAL symbol table.&amp;nbsp; By the time you try to use them, %CFT has finished executing and its LOCAL symbol table has been erased automatically.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Jun 2014 15:46:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-using-PROC-SQL-within-a-Macro/m-p/135846#M27564</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-06-10T15:46:36Z</dc:date>
    </item>
  </channel>
</rss>

