<?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: Macro Programing using %local in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Programing-using-local/m-p/511167#M137550</link>
    <description>&lt;P&gt;All variables in a macro that are not macro parameters or explicitly meant to be global should be local, to avoid unwanted side effects.&lt;/P&gt;</description>
    <pubDate>Wed, 07 Nov 2018 19:46:08 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-11-07T19:46:08Z</dc:date>
    <item>
      <title>Macro Programing using %local</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Programing-using-local/m-p/511132#M137541</link>
      <description>&lt;P&gt;I figured out a problem I had today because I had nested macros what used macro do loops which both start i=0. Because the inner macro went all the way to 70, when the outside macro referenced i for it's second pass, it thought i was 70 so it didn't need to do another loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is how to use %LOCAL to stop this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When using the local statement, do I need to refer to that variable as &amp;amp;i or &amp;amp;j? Is %LET &amp;amp;j= the right syntax or should it be &amp;amp;j.= %EVAL(&amp;amp;i.+1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LOCAL i j;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%DO &amp;amp;i.=0 %TO 70;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET &amp;amp;j = %EVAL(&amp;amp;i.+1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2018 19:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Programing-using-local/m-p/511132#M137541</guid>
      <dc:creator>pchappus</dc:creator>
      <dc:date>2018-11-07T19:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Programing using %local</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Programing-using-local/m-p/511143#M137544</link>
      <description>You should refer to either &amp;amp;i or &amp;amp;j depending on how they are used, since you've defined them both.&lt;BR /&gt;&lt;BR /&gt;I would suggest naming local vars local_i and local_j so they are clearly defined.  I don't think the '.' does anything, but I would remove it just in case.</description>
      <pubDate>Wed, 07 Nov 2018 19:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Programing-using-local/m-p/511143#M137544</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-11-07T19:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Programing using %local</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Programing-using-local/m-p/511161#M137549</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;When using the local statement, do I need to refer to that variable as &amp;amp;i or &amp;amp;j? Is %LET &amp;amp;j= the right syntax or should it be &amp;amp;j.= %EVAL(&amp;amp;i.+1);&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You wouldn't usually use %LET &amp;amp;J= ... ; in most cases the command is %LET J= ...;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;None of the macro referencing changes because you define a macro variable to be local.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2018 19:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Programing-using-local/m-p/511161#M137549</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-07T19:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Programing using %local</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Programing-using-local/m-p/511167#M137550</link>
      <description>&lt;P&gt;All variables in a macro that are not macro parameters or explicitly meant to be global should be local, to avoid unwanted side effects.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2018 19:46:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Programing-using-local/m-p/511167#M137550</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-07T19:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Programing using %local</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Programing-using-local/m-p/511180#M137553</link>
      <description>All local and outer vars would be available as if global to the "inner" macros unless "overridden" by the inner macro defining that name in a %local statement</description>
      <pubDate>Wed, 07 Nov 2018 20:22:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Programing-using-local/m-p/511180#M137553</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2018-11-07T20:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Programing using %local</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Programing-using-local/m-p/511251#M137558</link>
      <description>&lt;P&gt;What you have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%LOCAL i j;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%DO &amp;amp;i.=0 %TO 70;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%LET &amp;amp;j = %EVAL(&amp;amp;i.+1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What it should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%LOCAL i j;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%DO i=0 %TO 70;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%LET j = %EVAL(&amp;amp;i.+1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The correct syntax for referring to a macro variable has nothing at all to do with whether the variable is local or global.&amp;nbsp; %DO and %LET have the same syntax rules that apply to both local and global variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where the %LOCAL statement belongs:&amp;nbsp; within every macro definition that uses &amp;amp;i or &amp;amp;j.&amp;nbsp; (There are a few, complex exceptions that you are not likely to encounter.)&lt;/P&gt;</description>
      <pubDate>Thu, 08 Nov 2018 01:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Programing-using-local/m-p/511251#M137558</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-11-08T01:23:51Z</dc:date>
    </item>
  </channel>
</rss>

