<?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: &amp;quot;Statement is not valid&amp;quot; ... what's wrong with my macro? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/quot-Statement-is-not-valid-quot-what-s-wrong-with-my-macro/m-p/82920#M17898</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For commenting in macros it is best to use either the /* */ or %* instead of * preceding a statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Partially because of this behavior I almost never use the single statement comment starting with *. Then I don't have to change my commenting style when I'm within a macro.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 03 Aug 2012 14:50:55 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2012-08-03T14:50:55Z</dc:date>
    <item>
      <title>"Statement is not valid" ... what's wrong with my macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Statement-is-not-valid-quot-what-s-wrong-with-my-macro/m-p/82917#M17895</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was wondering if some kind person / SAS expert could tell me what I am doing wrong. The macro below ran before, but now it does not work and I cannot determine why. When I run the code below as a single run (i.e. not from a macro call) starting from *** Single Run %let i=1; .... until.... *** End single run; the code works fine. If I change %let i=2, it is also okay. Changing %let i=3,4,5....16 are all okay as simple SAS code. But then when I put in the %do loop and %macro statements, I get errors such as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"ERROR 180-322: or it is used out of proper order." and CREATE (as in: proc sql; create table) is underlined in red with 180 written underneath. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could someone tell me what I am doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro make_index;&lt;/P&gt;&lt;P&gt;%do i=1 %to 16;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*** Single run %let i=1;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table data_&amp;amp;&amp;amp;index_&amp;amp;i.._idx as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select L.*, R.ret_&amp;amp;&amp;amp;index_&amp;amp;i as ret_indx&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from data_&amp;amp;&amp;amp;index_&amp;amp;i as L left join &amp;amp;indx as R&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; on L.date = R.date and L.estper_beg&amp;lt;=R.date&amp;lt;=L.evtwin_end; quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort; by sdc_dealnum cusip8 date; run; &lt;/P&gt;&lt;P&gt;data data_&amp;amp;&amp;amp;index_&amp;amp;i.._idx; set data_&amp;amp;&amp;amp;index_&amp;amp;i.._idx; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; label&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ret_indx&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 'Return on Bond Index' &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; dpr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 'Daily Bond Price' &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; ret&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 'Daily Bond Return';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rename ret=ret_dpr date=dpr_date; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop bindx; run; &lt;/P&gt;&lt;P&gt;*** End single run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%end; &lt;/P&gt;&lt;P&gt;%mend; %make_index;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks so much!&lt;/P&gt;&lt;P&gt;Ian.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Aug 2012 01:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Statement-is-not-valid-quot-what-s-wrong-with-my-macro/m-p/82917#M17895</guid>
      <dc:creator>iank131</dc:creator>
      <dc:date>2012-08-03T01:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: "Statement is not valid" ... what's wrong with my macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Statement-is-not-valid-quot-what-s-wrong-with-my-macro/m-p/82918#M17896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I can see what is happening, but it's harder to explain why it should be so.&amp;nbsp; The crux of the matter is that SAS is interpreting this section of code differently, depending on whether it appears inside or outside a macro definition:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*** Single run %let i=1;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Outside of a macro definition, this is a comment statement followed by a PROC SQL statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Inside a macro definition, it gets interpreted differently, as if the code were:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let i=1;&lt;/P&gt;&lt;P&gt;*** Single run proc sql;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So there is no longer a PROC SQL statement, and the CREATE statement gives you the error message.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To get it to work is straightforward.&amp;nbsp; Get rid of the macro trigger.&amp;nbsp; For example, inside the macro definition, use:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*** Single run with i=1;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Aug 2012 02:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Statement-is-not-valid-quot-what-s-wrong-with-my-macro/m-p/82918#M17896</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-08-03T02:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: "Statement is not valid" ... what's wrong with my macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Statement-is-not-valid-quot-what-s-wrong-with-my-macro/m-p/82919#M17897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Astounding, you simply are ..... astounding!! &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; Such a simple thing!!&amp;nbsp; I just removed the commented&amp;nbsp; (i.e. asterisked) lines and .... it works!! This is why it worked before and not now. I was having problems with another macro I wrote and your explanation also helped me to solve that one too. Thanks again!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ian.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;Ian.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Aug 2012 06:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Statement-is-not-valid-quot-what-s-wrong-with-my-macro/m-p/82919#M17897</guid>
      <dc:creator>iank131</dc:creator>
      <dc:date>2012-08-03T06:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: "Statement is not valid" ... what's wrong with my macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Statement-is-not-valid-quot-what-s-wrong-with-my-macro/m-p/82920#M17898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For commenting in macros it is best to use either the /* */ or %* instead of * preceding a statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Partially because of this behavior I almost never use the single statement comment starting with *. Then I don't have to change my commenting style when I'm within a macro.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Aug 2012 14:50:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Statement-is-not-valid-quot-what-s-wrong-with-my-macro/m-p/82920#M17898</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-08-03T14:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: "Statement is not valid" ... what's wrong with my macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Statement-is-not-valid-quot-what-s-wrong-with-my-macro/m-p/82921#M17899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Macro will expand the macro statements inside of *; comments the same way it would inside of any other SAS statement.&lt;/P&gt;&lt;P&gt;You will also get in trouble if using unbalanced quotes inside of *; and %*; comments.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Even given these restrictions I still use *; comments inside of macro for comments that I want to appear in the SAS log when MPRINT is on.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%if &amp;amp;sort %then %do ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;* Sort dataset before using ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; proc sort ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by id;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But when the comment is on pure macro logic code then I would use %* ; comments as printing them with MPRINT would just clutter and confuse the log.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%if &amp;amp;sort %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%* Add by variable into keep list ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %let keep=&amp;amp;byvar &amp;amp;keep;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Aug 2012 15:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Statement-is-not-valid-quot-what-s-wrong-with-my-macro/m-p/82921#M17899</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-08-03T15:06:39Z</dc:date>
    </item>
  </channel>
</rss>

