<?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 %global macro issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604310#M175191</link>
    <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I have the below portion of the code which works perfectly fine but when I put the whole code inside another macro it fails. The section of the code looks like this.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%macro check_duplicate;&lt;BR /&gt;%global dup_list;&lt;BR /&gt;if &amp;amp;dup_list= %then %do;&lt;BR /&gt;%let dup_list=‘99999’;&lt;BR /&gt;%end;&lt;BR /&gt;%mend check_duplicate;&lt;BR /&gt;&lt;BR /&gt;%check_duplicate;&lt;BR /&gt;&lt;BR /&gt;This above section was working fine on my code but then I had to make some changes and put the whole code inside another macro and I am getting this error.&lt;BR /&gt;&lt;BR /&gt;ERROR: Attempt to %GLOBAL a name (DUP_LIST) which exists in a local environment.&lt;BR /&gt;&lt;BR /&gt;How can I handle this error without making much changes to the structure of the code.&lt;BR /&gt;&lt;BR /&gt;Any suggestions or ideas will be highly appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;Nick&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 14 Nov 2019 21:34:56 GMT</pubDate>
    <dc:creator>nickspencer</dc:creator>
    <dc:date>2019-11-14T21:34:56Z</dc:date>
    <item>
      <title>%global macro issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604310#M175191</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I have the below portion of the code which works perfectly fine but when I put the whole code inside another macro it fails. The section of the code looks like this.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%macro check_duplicate;&lt;BR /&gt;%global dup_list;&lt;BR /&gt;if &amp;amp;dup_list= %then %do;&lt;BR /&gt;%let dup_list=‘99999’;&lt;BR /&gt;%end;&lt;BR /&gt;%mend check_duplicate;&lt;BR /&gt;&lt;BR /&gt;%check_duplicate;&lt;BR /&gt;&lt;BR /&gt;This above section was working fine on my code but then I had to make some changes and put the whole code inside another macro and I am getting this error.&lt;BR /&gt;&lt;BR /&gt;ERROR: Attempt to %GLOBAL a name (DUP_LIST) which exists in a local environment.&lt;BR /&gt;&lt;BR /&gt;How can I handle this error without making much changes to the structure of the code.&lt;BR /&gt;&lt;BR /&gt;Any suggestions or ideas will be highly appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;Nick&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 14 Nov 2019 21:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604310#M175191</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2019-11-14T21:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: %global macro issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604324#M175196</link>
      <description>&lt;P&gt;The problem is with the "other" macro that calls this macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That other macro is creating a local macro variable named DUP_LIST.&amp;nbsp; Change the other macro so that it creates DUP_LIST as a global macro variable.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 22:04:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604324#M175196</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-11-14T22:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: %global macro issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604327#M175197</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt; I don’t think I understand when you say change other macro to create dup_list. Do you mean having the %global dup_list outside this check duplicate macro?</description>
      <pubDate>Thu, 14 Nov 2019 22:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604327#M175197</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2019-11-14T22:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: %global macro issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604330#M175200</link>
      <description>&lt;P&gt;That's an easy way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The variable is somehow getting created by the "other" macro as well.&amp;nbsp; So putting the %global statement outside of all macros should take care of the problem.&amp;nbsp; Alternatively, you could search for other code that also creates DUP_LIST.&amp;nbsp; But stick with the easy way if that sounds appropriate (add the %GLOBAL statement before running any macros).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 22:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604330#M175200</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-11-14T22:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: %global macro issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604334#M175203</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/206798"&gt;@nickspencer&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This above section was working fine on my code but then I had to make some changes and &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;put the whole code inside another macro&lt;/STRONG&gt;&lt;/FONT&gt; and I am getting this error.&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you saying you embedded your macro definitions? That's never a good idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro firstMacro ();

....


%macro secondMacro();
....

%mend secondMacro;

....
%mend firstMacro;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Nov 2019 22:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604334#M175203</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-14T22:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: %global macro issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604340#M175205</link>
      <description>&lt;P&gt;You cannot use %GLOBAL to define a macro variable in the GLOBAL scope if there is already a macro variable in another (local) scope with that same name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you want to make that macro variable as global to begin with?&amp;nbsp; Is so the macro can return a value to the caller?&amp;nbsp; Then just run the %GLOBAL statement when it is needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if not %symexist(dup_list) %then %global dup_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are just using the macro variable as INPUT to the macro and it doesn't exist then just make a local macro variable instead. No use cluttering the global scope with unneeded macro variables, that is how you got into this trouble to begin with.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if not %symexist(dup_list) %then %local dup_list;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Nov 2019 23:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604340#M175205</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-14T23:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: %global macro issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604341#M175206</link>
      <description>&lt;P&gt;Here's an idea: Provide the entire code of both macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That will help us avoid a lot of "if you did this then …" guesses.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 23:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/global-macro-issue/m-p/604341#M175206</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-14T23:38:22Z</dc:date>
    </item>
  </channel>
</rss>

