<?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: Simple macro to run a proc sql - error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92106#M19443</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear&lt;/P&gt;&lt;P&gt;You can have a view using the "Hash Iterator Object" inside this document "&lt;A href="http://support.sas.com/rnd/base/datastep/dot/iterator-getting-started.pdf"&gt;http://support.sas.com/rnd/base/datastep/dot/iterator-getting-started.pdf&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This one use a comparison between date and you can adapte using index funtion. The small table can be used as hash table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Oct 2012 08:18:06 GMT</pubDate>
    <dc:creator>lacrefa</dc:creator>
    <dc:date>2012-10-12T08:18:06Z</dc:date>
    <item>
      <title>Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92090#M19427</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a rather simple macro that I am using to run a proc sql. I am not able to resolve the error. Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro _countrec_updatetaxid(taxid);&lt;BR /&gt;proc sql;&lt;BR /&gt;create table work.extract as &lt;BR /&gt;(&lt;BR /&gt;select count(*) :into rec_cnt from &amp;amp;FLDR..&amp;amp;FLDR._mcid_etg&lt;BR /&gt;where etg1tax contains &lt;BR /&gt;('&amp;amp;taxid')&lt;/P&gt;&lt;P&gt;); &lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;%mend _countrec_updatetaxid;&lt;BR /&gt;*%local taxid rc;&lt;BR /&gt;%let taxid=43612589;&lt;BR /&gt;%let rc=%_countrec_updatetaxid(&amp;amp;taxid);&lt;BR /&gt;%put "The number of records for tax id is" &amp;amp;rc;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The error is&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the invoked macro "_COUNTREC_UPDATETAXID".&lt;/P&gt;&lt;P&gt;29&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql; create table work.extract as&amp;nbsp; ( select count(*) :into rec_cnt from &amp;amp;FLDR..&amp;amp;FLDR._mcid_etg where etg1tax&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ______&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 180&lt;/P&gt;&lt;P&gt;29&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ! contains&amp;nbsp; ('&amp;amp;taxid')&amp;nbsp; );&amp;nbsp; QUIT;&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think the bug is small but I am not able to notice what is wrong with the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;saspert.&lt;/P&gt;&lt;P&gt;PS: The bigger plan is to invoke the above macro for all the records of a dataset using call execute statement. That is why I am testing this macro first.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: saspert So here is the crux of my issue. I have a main sas dataset &amp;amp;FLDR..&amp;amp;FLDR._mcid_etg with several hundreds of taxids. Some of them (around 83 distinct taxids) have a missing leading 0 for them. Now, I have all 83 of them in a separate dataset called work.msng_taxid. So, I need to somehow do this repetitive task of fetching 1 taxid, counting the # of records in &amp;amp;FLDR..&amp;amp;FLDR._mcid_etg and updating it with the correct taxid. In the above example, 43612589 needs to be replaced with 043612589.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Oct 2012 22:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92090#M19427</guid>
      <dc:creator>saspert</dc:creator>
      <dc:date>2012-10-10T22:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92091#M19428</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; ('&amp;amp;taxid') maybe should be "&amp;amp;taxid" to resolve the macro variable reference and the parantheses shouldn't be needed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Oct 2012 22:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92091#M19428</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-10-10T22:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92092#M19429</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Without getting into what you are really trying to do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) the :into&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; rec_cnt&lt;/SPAN&gt; really should be into :rec_cnt&lt;/P&gt;&lt;P&gt;2) you are trying to create a table (containing nothing) AND create a macro variable.&amp;nbsp; Don't you really want a proc sql noprint with no create table?&lt;/P&gt;&lt;P&gt;3) as ballardw mentioned, the macro variable should be within double quotes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Oct 2012 22:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92092#M19429</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-10-10T22:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92093#M19430</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Art,&lt;/P&gt;&lt;P&gt;So I modified my code but still am getting the same error. Now, if remove the %macro wrapper, it seems to be running fine. &lt;/P&gt;&lt;P&gt;NOTE: Line generated by the invoked macro "_COUNTREC_UPDATETAXID".&lt;/P&gt;&lt;P&gt;30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql noprint;&amp;nbsp;&amp;nbsp; select count(*) into :rec_cnt&amp;nbsp; from &amp;amp;FLDR..&amp;amp;FLDR._mcid_etg where etg1tax contains&amp;nbsp; '&amp;amp;taxid'&amp;nbsp;&amp;nbsp; ;&amp;nbsp; QUIT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ______&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 180&lt;/P&gt;&lt;P&gt;30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ! ;&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;saspert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 00:29:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92093#M19430</guid>
      <dc:creator>saspert</dc:creator>
      <dc:date>2012-10-11T00:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92094#M19431</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks ballardw - i modified as per your suggestion. please see above if my updated code is correct.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 00:30:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92094#M19431</guid>
      <dc:creator>saspert</dc:creator>
      <dc:date>2012-10-11T00:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92095#M19432</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you need to change '&amp;amp;taxid' to "&amp;amp;taxid".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 01:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92095#M19432</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-10-11T01:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92096#M19433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;The main problem is this statement:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;%let rc=&lt;/SPAN&gt;&lt;STRONG style="background-color: #ffffff; font-family: 'courier new', courier;"&gt;&lt;SPAN style="color: #ff0000;"&gt;%_countrec_updatetaxid(&amp;amp;taxid)&lt;/SPAN&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;SAS macros are not &lt;/SPAN&gt;functions that return values.&amp;nbsp; They are mainly just a way to generate code to reduce repetitive typing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;In this case the existence the %LET statement preceding the macro call will cause the generated code to look like:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let rc=&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;proc sql ;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;create .... &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So the macro variable RC will be set to "PROC SQL" and the CREATE statement will generate an error message because it is not inside of a PROC SQL/QUIT block.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 02:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92096#M19433</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-10-11T02:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92097#M19434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Tom for pointing out the glaring mistake. So, I guess I have to declare a global macro variable inside the macro program to store the output of the proc sql count and then use it outside the macro code?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 02:27:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92097#M19434</guid>
      <dc:creator>saspert</dc:creator>
      <dc:date>2012-10-11T02:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92098#M19435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The macro variable just needs to be defined outside of the scope of the macro for the value to continue to be visible after the macro ends.&lt;/P&gt;&lt;P&gt;&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;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro _countrec_updatetaxid(taxid);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select count(*) into :rec_cnt&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; from &amp;amp;FLDR..&amp;amp;FLDR._mcid_etg&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; where etg1tax contains "&amp;amp;taxid"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend _countrec_updatetaxid;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let rec_cnt=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;%_countrec_updatetaxid(XYZ);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;%put Record count for XYZ = &amp;amp;rec_cnt ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 11:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92098#M19435</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-10-11T11:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92099#M19436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Tom,&lt;/P&gt;&lt;P&gt;I would like to call this macro for each observation in a dataset. Would this work?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set HrtgMsngTaxids ;&lt;/P&gt;&lt;P&gt;put taxid=;&lt;/P&gt;&lt;P&gt;call symput('_countrec_updatetaxid',taxid);&lt;/P&gt;&lt;P&gt;put &amp;amp;cnt_rec;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 12:14:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92099#M19436</guid>
      <dc:creator>saspert</dc:creator>
      <dc:date>2012-10-11T12:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92100#M19437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I remember well you can do that by 2 main way :&lt;/P&gt;&lt;P&gt;1 filename xxx temp lrecl=256;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set HrtgMsngTaxids ;&lt;/P&gt;&lt;P&gt;length text $200;&lt;/P&gt;&lt;P&gt;file xxx;&lt;/P&gt;&lt;P&gt;text=' &lt;SPAN style="font-family: 'courier new', courier;"&gt;%let rec_cnt=0;';output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;text=trim(text)||' &lt;SPAN style="background-color: #ffffff; font-family: 'courier new', courier;"&gt;%_countrec_updatetaxid(&lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;'||taxid||');';&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'courier new', courier;"&gt;text=trim(text)||'%put Record count for XYZ = &amp;amp;rec_cnt ;';&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'courier new', courier;"&gt;put text;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;%inc xxx;&lt;/P&gt;&lt;P&gt;filename xxx;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2 instead to put statement in temp file, use a&amp;nbsp; : call execute(text)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 13:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92100#M19437</guid>
      <dc:creator>lacrefa</dc:creator>
      <dc:date>2012-10-11T13:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92101#M19438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are headed toward CALL EXECUTE, there is an issue to keep in mind.&amp;nbsp; The PROC SQL statements generated by CALL EXECUTE will stack up and execute once the DATA step that generates them has completed.&amp;nbsp; But any macro language statements generated by CALL EXECUTE (%LET, %PUT, for example) will execute right away, before the current DATA step has completed, and before any of the PROC SQL steps have run.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 14:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92101#M19438</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-10-11T14:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92102#M19439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks astounding - i noticed that when i ran the datastep with only 2 records. It seem to complete the datastep first and then execute the macro. Anyway, I went ahead and manually updated the dataset since I am short of time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;saspert.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 14:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92102#M19439</guid>
      <dc:creator>saspert</dc:creator>
      <dc:date>2012-10-11T14:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92103#M19440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, You need double quatation, instead single one, for the macro variable &amp;amp;taxid to work. &lt;BR /&gt;So try&lt;/P&gt;&lt;P&gt;where etg1tax contains &lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;("&amp;amp;taxid")&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Good luck!&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 16:04:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92103#M19440</guid>
      <dc:creator>qian</dc:creator>
      <dc:date>2012-10-11T16:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92104#M19441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could make the macro return a value if you really have to have it that way, but it's not great programming practice in SAS:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%MACRO checkForVars(var1,var2,var3);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let var1=%sysfunc(dequote(&amp;amp;var1));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let var2=%sysfunc(dequote(&amp;amp;var2));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let var3=%sysfunc(dequote(&amp;amp;var3));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let dsid=%sysfunc(open(&amp;amp;inDS));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let check=%sysfunc(varnum(&amp;amp;dsid,&amp;amp;var1));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if &amp;amp;check ^= 0 %then %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let check=%sysfunc(varnum(&amp;amp;dsid,&amp;amp;var2));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if &amp;amp;check ^= 0 %then %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let check=%sysfunc(varnum(&amp;amp;dsid,&amp;amp;var3));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let rc=%sysfunc(close(&amp;amp;dsid));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if &amp;amp;check ^= 0 %then %let out=Y;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let rc=%sysfunc(close(&amp;amp;dsid));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let out=N;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt; &amp;amp;out&lt;BR /&gt; %MEND checkForVars;&lt;BR /&gt; %let end_date_flg="%checkForVars('cdexpm','cdexpd','cdexpy')";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notice the missing semicolon at the &amp;amp;out part of the macro. This will send the value of the variable out back to wherever the macro was called from. In this case, this macro sends back a value of "Y" or "N" to indicate whether one of the three variables passed to it exists in the dataset.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 17:49:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92104#M19441</guid>
      <dc:creator>JeremyCAdams</dc:creator>
      <dc:date>2012-10-11T17:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92105#M19442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If that is what you want to do then you do not want to use a macro or even macro variables.&lt;/P&gt;&lt;P&gt;Just join the table and count the records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql noprint ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;create table want as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; select distinct &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.taxid &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , count(etg1tax) as cnt_rec&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; from hrtgmsngtaxids a left join&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;FLDR..&amp;amp;FLDR._mcid_etg b&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; on&amp;nbsp; b.etg1tax contains trim(a.taxid)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by a.taxid&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 18:57:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92105#M19442</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-10-11T18:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: Simple macro to run a proc sql - error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92106#M19443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear&lt;/P&gt;&lt;P&gt;You can have a view using the "Hash Iterator Object" inside this document "&lt;A href="http://support.sas.com/rnd/base/datastep/dot/iterator-getting-started.pdf"&gt;http://support.sas.com/rnd/base/datastep/dot/iterator-getting-started.pdf&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This one use a comparison between date and you can adapte using index funtion. The small table can be used as hash table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 08:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-macro-to-run-a-proc-sql-error/m-p/92106#M19443</guid>
      <dc:creator>lacrefa</dc:creator>
      <dc:date>2012-10-12T08:18:06Z</dc:date>
    </item>
  </channel>
</rss>

