<?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 local and global in macros examples in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/local-and-global-in-macros-examples/m-p/543429#M150217</link>
    <description>&lt;P&gt;can any one details examples about local and global macros variables&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Mar 2019 07:51:34 GMT</pubDate>
    <dc:creator>BrahmanandaRao</dc:creator>
    <dc:date>2019-03-15T07:51:34Z</dc:date>
    <item>
      <title>local and global in macros examples</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-and-global-in-macros-examples/m-p/543429#M150217</link>
      <description>&lt;P&gt;can any one details examples about local and global macros variables&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 07:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-and-global-in-macros-examples/m-p/543429#M150217</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2019-03-15T07:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: local and global in macros examples</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-and-global-in-macros-examples/m-p/543430#M150218</link>
      <description>&lt;P&gt;Please read the documentation found at &lt;A href="http://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=n19aprg65bcylon19p8sd9ur7ucg.htm&amp;amp;locale=de" target="_blank"&gt;http://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=n19aprg65bcylon19p8sd9ur7ucg.htm&amp;amp;locale=de&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 08:09:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-and-global-in-macros-examples/m-p/543430#M150218</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-15T08:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: local and global in macros examples</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-and-global-in-macros-examples/m-p/543431#M150219</link>
      <description>&lt;P&gt;Maxim 1: Read the Documentation&lt;/P&gt;
&lt;P&gt;(documentation.sas.com, select Macro Language Reference, Understanding and Using the Macro Facility, &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=n10i4tmalsyhgxn1hj4ud13ff074.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;Scopes of Macro Variables&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;Everything you need to know about macro variable scope, including examples.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 08:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-and-global-in-macros-examples/m-p/543431#M150219</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-15T08:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: local and global in macros examples</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-and-global-in-macros-examples/m-p/543467#M150231</link>
      <description>&lt;P&gt;Interestingly, the two links you got, from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; do not really answer your questions. The first reference says very little about the scope of macro variables, the second actually contains a factual error:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-paragraph" id="n1to19m5xoaqy5n1w75zuei6vbqz" style="background-color: transparent; box-sizing: border-box; color: #333333; font-family: &amp;amp;quot; avenirnext&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14.06px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-top: 19.69px; orphans: 2; position: relative; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;A local symbol table can be created by any of the following:&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;DIV class="xis-listUnordered" style="background-color: transparent; box-sizing: border-box; color: #333333; font-family: &amp;amp;quot; avenirnext&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14.06px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;
&lt;BLOCKQUOTE&gt;
&lt;UL style="box-sizing: border-box; list-style-image: none; list-style-type: disc; margin-bottom: 0px; margin-left: 0px; margin-top: 0px; padding-left: 35.16px;"&gt;
&lt;LI style="box-sizing: border-box;"&gt;
&lt;DIV class="xis-item" id="n1omq4atr6psepn1ijwrk6m51pt2" style="box-sizing: border-box; margin-top: 19.69px;"&gt;
&lt;DIV class="xis-paraSimpleFirst" id="n1ji8f2i73qcahn0z6wutvhqfa60" style="box-sizing: border-box; display: inline; margin-top: 0px;"&gt;the presence of one or more macro parameters&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI style="box-sizing: border-box;"&gt;
&lt;DIV class="xis-item" id="p05tq2kjycm49gn1dp0zi9trx1dx" style="box-sizing: border-box; margin-top: 19.69px;"&gt;
&lt;DIV class="xis-paraSimpleFirst" id="p06vuylh6zpfx0n1384ec1avnn25" style="box-sizing: border-box; display: inline; margin-top: 0px;"&gt;a %LOCAL statement&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI style="box-sizing: border-box;"&gt;
&lt;DIV class="xis-item" id="n1jqglbdd6gxcan1qe6ts7z6ga2b" style="box-sizing: border-box; margin-top: 19.69px;"&gt;
&lt;DIV class="xis-paraSimpleFirst" id="p0li4em5fludcjn15dnvjh151vx8" style="box-sizing: border-box; display: inline; margin-top: 0px; position: relative;"&gt;macro statements that define macro variables, such as %LET and the iterative %DO statement (&lt;FONT color="#ff0000"&gt;if the &lt;SPAN class="ng-scope" style="box-sizing: border-box;" data-gloss-modified="" data-gloss-item="1"&gt;&lt;A class="glossLink ng-scope" style="background-color: transparent; box-sizing: border-box; color: #333333; text-decoration: none;" target="_blank"&gt;&lt;SPAN class="xis-glossTerm ng-scope" style="border-bottom-color: #353535; border-bottom-style: dashed; border-bottom-width: 1px; box-sizing: border-box; color: #000000; cursor: help; outline-color: invert; outline-style: none; outline-width: 0px; position: relative; text-decoration: none;" data-gloss-term="1"&gt;variable&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt; does not already exist globally or a %GLOBAL statement is not used&lt;/FONT&gt;)&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/BLOCKQUOTE&gt;
&lt;/DIV&gt;
&lt;P&gt;The statement marked in red is not correct. A local symbol table is created if a macro variable is defined that does not exist in the calling environment. But that does not necessarily mean a %GLOBAL variable, the variable could also be %LOCAL to a calling macro, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro a;
  %local i;
  %do i=1 %to 5;
     %b;
     %end;
%mend;

%macro b;
  %do i=1 %to 3;
    %put Hello World;
    %end;
%mend;&lt;BR /&gt;&lt;BR /&gt;%a;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This very silly example shows the danger of forgetting to declare your macro variables %LOCAL. If you submit this, it will keep writing "Hello World" in the log, until the log runs full or you press &amp;lt;ctrl-break&amp;gt;. Why? Because the I variable in %B is the same as the one in %A. So, there was no %GLOBAL I variable, yet no local symbol table in %B either.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Forgetting to declare macro variables %LOCAL is a very common mistake. Many years ago we even had to write SAS Institute and ask them to declare the variable I %LOCAL in one of their utility macros (I think it was %VERIFY).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 10:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-and-global-in-macros-examples/m-p/543467#M150231</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-03-15T10:15:04Z</dc:date>
    </item>
  </channel>
</rss>

