<?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: What to do when calling a macro where variables have not been declared with LOCAL scope? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-to-do-when-calling-a-macro-where-variables-have-not-been/m-p/520286#M141049</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can create an intermediary macro that declares index as local :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro cannot_modify;
  %let index = 123;
%mend;

%macro can_modify;
    %local index;
    %cannot_modify;
%mend; 

%macro wrapper;

  %do index = 1 %to 10;
    %can_modify;

	%put &amp;amp;=index.;
  %end;

%mend;

%wrapper;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 11 Dec 2018 08:36:16 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2018-12-11T08:36:16Z</dc:date>
    <item>
      <title>What to do when calling a macro where variables have not been declared with LOCAL scope?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-to-do-when-calling-a-macro-where-variables-have-not-been/m-p/520246#M141042</link>
      <description>&lt;P&gt;Hi everyone.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am calling a macro (which has been written by somebody else) inside a wrapper macro. The macro that is being called cannot be modified. The author of the called macro did not declare variables used within that macro using LOCAL scope. So, if I call this macro, it may modify variables in the wrapper macro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro cannot_modify;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let index = 123;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro wrapper;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Intention is to run %cannot_modify 10 times, but it will only run once. */&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do index = 1 %to 10;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; %cannot_modify;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'd like to know is: is there some way of protecting the variables in the wrapper code so that the called macro cannot modify them, without modifying the called macro?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope I've explained this clearly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks very much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 05:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-to-do-when-calling-a-macro-where-variables-have-not-been/m-p/520246#M141042</guid>
      <dc:creator>ben12</dc:creator>
      <dc:date>2018-12-11T05:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: What to do when calling a macro where variables have not been declared with LOCAL scope?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-to-do-when-calling-a-macro-where-variables-have-not-been/m-p/520286#M141049</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can create an intermediary macro that declares index as local :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro cannot_modify;
  %let index = 123;
%mend;

%macro can_modify;
    %local index;
    %cannot_modify;
%mend; 

%macro wrapper;

  %do index = 1 %to 10;
    %can_modify;

	%put &amp;amp;=index.;
  %end;

%mend;

%wrapper;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Dec 2018 08:36:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-to-do-when-calling-a-macro-where-variables-have-not-been/m-p/520286#M141049</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-12-11T08:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: What to do when calling a macro where variables have not been declared with LOCAL scope?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-to-do-when-calling-a-macro-where-variables-have-not-been/m-p/520297#M141053</link>
      <description>&lt;P&gt;If you find you need to do something outside of locally scoped macro variables, which is not at a system level, then I would conclude that there is a far better method to solve your particular problem, and that proceedng down the route of globalising, or wrapping variables will just make your code messy and unmaintainable.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 09:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-to-do-when-calling-a-macro-where-variables-have-not-been/m-p/520297#M141053</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-12-11T09:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: What to do when calling a macro where variables have not been declared with LOCAL scope?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-to-do-when-calling-a-macro-where-variables-have-not-been/m-p/521012#M141331</link>
      <description>Looks good - I think that might solve my problem. Thank you!</description>
      <pubDate>Wed, 12 Dec 2018 21:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-to-do-when-calling-a-macro-where-variables-have-not-been/m-p/521012#M141331</guid>
      <dc:creator>ben12</dc:creator>
      <dc:date>2018-12-12T21:23:46Z</dc:date>
    </item>
  </channel>
</rss>

