<?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: why do we need % in front of syntax inside a macro? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/why-do-we-need-in-front-of-syntax-inside-a-macro/m-p/517991#M140137</link>
    <description>&lt;P&gt;This is a misunderstanding of what macro is and how it works.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro is a text generator, a find/replace system if you will.&amp;nbsp; The text of your program is fed into the macro pre-processor which does a find replace all occurrences of macro variables by pattern &amp;amp; -- ., and replaces those with the value in the macro variable.&amp;nbsp; It then expands any macro code indicated by the %.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Out of that process you then have the full plain Base SAS code which then goes into the compiler to be executed.&amp;nbsp; Therefore if you had:&lt;/P&gt;
&lt;PRE&gt;%macro something ();
  %do i=1 %to 3;
    a=1;
  %end;
%mend something ();
&lt;/PRE&gt;
&lt;P&gt;Then then macro pre-processor knows that the %do loop is its part to expand the text out e.g. this will create after being through the macro pre-processor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;a=1;
a=1;
a=1;&lt;/PRE&gt;
&lt;P&gt;Repeat the text 3 times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you replaced that with no % as:&lt;/P&gt;
&lt;PRE&gt;%macro something ();
  do i=1 to 3;
    a=1;
  end;
%mend something ();&lt;/PRE&gt;
&lt;P&gt;This would put in the text file:&lt;/P&gt;
&lt;PRE&gt;do i=1 to 3;
  a=1;
end;&lt;/PRE&gt;
&lt;P&gt;Note that in this instance the macro pre-processor is&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;not&lt;/STRONG&gt;&lt;/U&gt; doing the loop, it just generates that text.&amp;nbsp; When this code is fed into the compiler within a datastep then the loop is executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 03 Dec 2018 09:16:04 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-12-03T09:16:04Z</dc:date>
    <item>
      <title>why do we need % in front of syntax inside a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-do-we-need-in-front-of-syntax-inside-a-macro/m-p/517989#M140135</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Why do we need % in front of some syntax keyword such as do, end, for, put ...etc... when inside a macro? I tried without the % and it works fine.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 08:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-do-we-need-in-front-of-syntax-inside-a-macro/m-p/517989#M140135</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2018-12-03T08:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: why do we need % in front of syntax inside a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-do-we-need-in-front-of-syntax-inside-a-macro/m-p/517990#M140136</link>
      <description>&lt;P&gt;% and &amp;amp; are the so-called "macro triggers", which instruct SAS to hand over the interpretation of the next item to the macro preprocessor.&lt;/P&gt;
&lt;P&gt;"do" and "%do" are NOT the same. "do" is a data step statement, "%do" is a macro statement, no matter if they are used in a macro or in open code.&lt;/P&gt;
&lt;P&gt;If you supply your code that "worked" with and without %, I can explain why that happens.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 09:08:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-do-we-need-in-front-of-syntax-inside-a-macro/m-p/517990#M140136</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-03T09:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: why do we need % in front of syntax inside a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-do-we-need-in-front-of-syntax-inside-a-macro/m-p/517991#M140137</link>
      <description>&lt;P&gt;This is a misunderstanding of what macro is and how it works.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro is a text generator, a find/replace system if you will.&amp;nbsp; The text of your program is fed into the macro pre-processor which does a find replace all occurrences of macro variables by pattern &amp;amp; -- ., and replaces those with the value in the macro variable.&amp;nbsp; It then expands any macro code indicated by the %.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Out of that process you then have the full plain Base SAS code which then goes into the compiler to be executed.&amp;nbsp; Therefore if you had:&lt;/P&gt;
&lt;PRE&gt;%macro something ();
  %do i=1 %to 3;
    a=1;
  %end;
%mend something ();
&lt;/PRE&gt;
&lt;P&gt;Then then macro pre-processor knows that the %do loop is its part to expand the text out e.g. this will create after being through the macro pre-processor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;a=1;
a=1;
a=1;&lt;/PRE&gt;
&lt;P&gt;Repeat the text 3 times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you replaced that with no % as:&lt;/P&gt;
&lt;PRE&gt;%macro something ();
  do i=1 to 3;
    a=1;
  end;
%mend something ();&lt;/PRE&gt;
&lt;P&gt;This would put in the text file:&lt;/P&gt;
&lt;PRE&gt;do i=1 to 3;
  a=1;
end;&lt;/PRE&gt;
&lt;P&gt;Note that in this instance the macro pre-processor is&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;not&lt;/STRONG&gt;&lt;/U&gt; doing the loop, it just generates that text.&amp;nbsp; When this code is fed into the compiler within a datastep then the loop is executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 09:16:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-do-we-need-in-front-of-syntax-inside-a-macro/m-p/517991#M140137</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-12-03T09:16:04Z</dc:date>
    </item>
  </channel>
</rss>

