<?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 Variable not Resolving in Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Global-Variable-not-Resolving-in-Macro/m-p/455672#M115315</link>
    <description>&lt;P&gt;I am generating a Global variable using a SELECT :INTO and it was resolving before using a macro. Now I need to bound a large part of my code inside a macro and use a conditional&amp;nbsp;CALL EXECUTE as a means to bypass or run my code. Now that I am generating this variable inside&amp;nbsp;the macro, it is not resolving.&amp;nbsp;Below is a simplified version of the code. Thanks for the help!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO FCST_CHK1(IVINC);
%GLOBAL &amp;amp;IVINC; /* INCENTIVE FILE VIN COUNT */

PROC SQL; /* CREATE VIN COUNT FOR INCENTIVE FILE TEST */
	SELECT COUNT(VIN17)
	INTO :&amp;amp;IVINC
	FROM INCV;
	
DATA _NULL_; /* TEST IF INCENTIVE FILE IS EMPTY */
	IF &amp;amp;IVINC = 0 THEN DO;
		FILE RETURNC;
		PUT	@01	'RETURN CODE 01: THE INCENTIVE FILE IS EMPTY';
		ABORT RETURN 01;
	END;

%MEND FCST_CHK1;

DATA _NULL_;
	IF "&amp;amp;FCST_Y" = '0' THEN CALL EXECUTE('%FCST_CHK1(&amp;amp;IVINC)');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Apr 2018 16:52:36 GMT</pubDate>
    <dc:creator>DonnieJ</dc:creator>
    <dc:date>2018-04-19T16:52:36Z</dc:date>
    <item>
      <title>Global Variable not Resolving in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Variable-not-Resolving-in-Macro/m-p/455672#M115315</link>
      <description>&lt;P&gt;I am generating a Global variable using a SELECT :INTO and it was resolving before using a macro. Now I need to bound a large part of my code inside a macro and use a conditional&amp;nbsp;CALL EXECUTE as a means to bypass or run my code. Now that I am generating this variable inside&amp;nbsp;the macro, it is not resolving.&amp;nbsp;Below is a simplified version of the code. Thanks for the help!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO FCST_CHK1(IVINC);
%GLOBAL &amp;amp;IVINC; /* INCENTIVE FILE VIN COUNT */

PROC SQL; /* CREATE VIN COUNT FOR INCENTIVE FILE TEST */
	SELECT COUNT(VIN17)
	INTO :&amp;amp;IVINC
	FROM INCV;
	
DATA _NULL_; /* TEST IF INCENTIVE FILE IS EMPTY */
	IF &amp;amp;IVINC = 0 THEN DO;
		FILE RETURNC;
		PUT	@01	'RETURN CODE 01: THE INCENTIVE FILE IS EMPTY';
		ABORT RETURN 01;
	END;

%MEND FCST_CHK1;

DATA _NULL_;
	IF "&amp;amp;FCST_Y" = '0' THEN CALL EXECUTE('%FCST_CHK1(&amp;amp;IVINC)');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 16:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Variable-not-Resolving-in-Macro/m-p/455672#M115315</guid>
      <dc:creator>DonnieJ</dc:creator>
      <dc:date>2018-04-19T16:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Global Variable not Resolving in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Variable-not-Resolving-in-Macro/m-p/455675#M115317</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%GLOBAL&lt;/SPAN&gt; IVINC&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I don't think you need the ampersand, otherwise it resolves to whatever value &amp;amp;ivinc has so you're setting the wrong thing to be global.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/204221"&gt;@DonnieJ&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I am generating a Global variable using a SELECT :INTO and it was resolving before using a macro. Now I need to bound a large part of my code inside a macro and use a conditional&amp;nbsp;CALL EXECUTE as a means to bypass or run my code. Now that I am generating this variable inside&amp;nbsp;the macro, it is not resolving.&amp;nbsp;Below is a simplified version of the code. Thanks for the help!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO FCST_CHK1(IVINC);
%GLOBAL &amp;amp;IVINC; /* INCENTIVE FILE VIN COUNT */

PROC SQL; /* CREATE VIN COUNT FOR INCENTIVE FILE TEST */
	SELECT COUNT(VIN17)
	INTO :&amp;amp;IVINC
	FROM INCV;
	
DATA _NULL_; /* TEST IF INCENTIVE FILE IS EMPTY */
	IF &amp;amp;IVINC = 0 THEN DO;
		FILE RETURNC;
		PUT	@01	'RETURN CODE 01: THE INCENTIVE FILE IS EMPTY';
		ABORT RETURN 01;
	END;

%MEND FCST_CHK1;

DATA _NULL_;
	IF "&amp;amp;FCST_Y" = '0' THEN CALL EXECUTE('%FCST_CHK1(&amp;amp;IVINC)');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 16:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Variable-not-Resolving-in-Macro/m-p/455675#M115317</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-19T16:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: Global Variable not Resolving in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Variable-not-Resolving-in-Macro/m-p/455687#M115323</link>
      <description>&lt;P&gt;I tried that first, but it still did not resolve.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 17:15:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Variable-not-Resolving-in-Macro/m-p/455687#M115323</guid>
      <dc:creator>DonnieJ</dc:creator>
      <dc:date>2018-04-19T17:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: Global Variable not Resolving in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Variable-not-Resolving-in-Macro/m-p/455695#M115328</link>
      <description>Macro variables do not resolve in single quotes. I can't run your code to test it ... so showing what errors you're getting or 'not resolving' would help a lot here.</description>
      <pubDate>Thu, 19 Apr 2018 17:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Variable-not-Resolving-in-Macro/m-p/455695#M115328</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-19T17:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Global Variable not Resolving in Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Variable-not-Resolving-in-Macro/m-p/455713#M115338</link>
      <description>&lt;P&gt;This combination just by itself would create an error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro FCST_CHK1 (IVINC);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %global IVINC;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your macro has a local macro variable named IVINC.&amp;nbsp; You cannot move it to the global table by using a %GLOBAL statement.&amp;nbsp; In fact, SAS will assume that's what you want to do, will not allow it, and will give you an error message so that you don't think that this actually worked.&amp;nbsp; You would see that if&amp;nbsp; you were to try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro FCST_CHK1(IVINC);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %global IVINC;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can easily get around the problem by letting SQL populate the local variable (into : ivinc), and copying the result to a global variable.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%global new_name;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then after the PROC SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let new_name = &amp;amp;ivinc;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 18:05:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Variable-not-Resolving-in-Macro/m-p/455713#M115338</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-19T18:05:04Z</dc:date>
    </item>
  </channel>
</rss>

