<?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 Macro variable not resolving. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving/m-p/883824#M349169</link>
    <description>&lt;DIV&gt;Hi Co's,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Can you please suggest, what is the issue with this code, and it is unable to resolve macro variable from &lt;FONT color="#FF0000"&gt;highlighted&lt;/FONT&gt;.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%macro macro1(server1);&lt;/DIV&gt;
&lt;DIV&gt;data have_&amp;amp;server1.;&lt;/DIV&gt;
&lt;DIV&gt;storage_cnt=100;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc sql noprint;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; select storage_cnt into :storage_cnt_&amp;amp;server1. from have_&amp;amp;server1.;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;quit;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%put storage_cnt_&amp;amp;server1.=&amp;amp;&amp;amp;storage_cnt_&amp;amp;server1.;&lt;/DIV&gt;
&lt;DIV&gt;%mend macro1;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%macro1(SASAPP1);&lt;/DIV&gt;
&lt;DIV&gt;%macro1(SASAPP2);&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;DATA _null_;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color="#FF0000"&gt;total_storage=SUM(&amp;amp;storage_cnt_SASAPP1.,&amp;amp;storage_cnt_SASAPP2.);&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;call symput('total_storage',total_storage);&lt;/DIV&gt;
&lt;DIV&gt;RUN;&lt;/DIV&gt;
&lt;DIV&gt;%put total_storage=&amp;amp;total_storage.;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color="#FF0000"&gt;ERROR:&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV class="sasSource"&gt;89 DATA _null_;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;90 total_storage=SUM(&amp;amp;storage_cnt_SASAPP1.,&amp;amp;storage_cnt_SASAPP2.);&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;_&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;386&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;200&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;76&lt;/DIV&gt;
&lt;DIV id="sasLogWarning1_1688674788999" class="sasWarning"&gt;&lt;FONT color="#FF0000"&gt;WARNING: Apparent symbolic reference STORAGE_CNT_SASAPP1 not resolved.&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV id="sasLogWarning2_1688674788999" class="sasWarning"&gt;&lt;FONT color="#FF0000"&gt;WARNING: Apparent symbolic reference STORAGE_CNT_SASAPP2 not resolved.&lt;/FONT&gt;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Thu, 06 Jul 2023 20:28:32 GMT</pubDate>
    <dc:creator>kumarsandip975</dc:creator>
    <dc:date>2023-07-06T20:28:32Z</dc:date>
    <item>
      <title>Macro variable not resolving.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving/m-p/883824#M349169</link>
      <description>&lt;DIV&gt;Hi Co's,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Can you please suggest, what is the issue with this code, and it is unable to resolve macro variable from &lt;FONT color="#FF0000"&gt;highlighted&lt;/FONT&gt;.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%macro macro1(server1);&lt;/DIV&gt;
&lt;DIV&gt;data have_&amp;amp;server1.;&lt;/DIV&gt;
&lt;DIV&gt;storage_cnt=100;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc sql noprint;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; select storage_cnt into :storage_cnt_&amp;amp;server1. from have_&amp;amp;server1.;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;quit;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%put storage_cnt_&amp;amp;server1.=&amp;amp;&amp;amp;storage_cnt_&amp;amp;server1.;&lt;/DIV&gt;
&lt;DIV&gt;%mend macro1;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%macro1(SASAPP1);&lt;/DIV&gt;
&lt;DIV&gt;%macro1(SASAPP2);&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;DATA _null_;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color="#FF0000"&gt;total_storage=SUM(&amp;amp;storage_cnt_SASAPP1.,&amp;amp;storage_cnt_SASAPP2.);&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;call symput('total_storage',total_storage);&lt;/DIV&gt;
&lt;DIV&gt;RUN;&lt;/DIV&gt;
&lt;DIV&gt;%put total_storage=&amp;amp;total_storage.;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color="#FF0000"&gt;ERROR:&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV class="sasSource"&gt;89 DATA _null_;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;90 total_storage=SUM(&amp;amp;storage_cnt_SASAPP1.,&amp;amp;storage_cnt_SASAPP2.);&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;_&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;386&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;200&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;76&lt;/DIV&gt;
&lt;DIV id="sasLogWarning1_1688674788999" class="sasWarning"&gt;&lt;FONT color="#FF0000"&gt;WARNING: Apparent symbolic reference STORAGE_CNT_SASAPP1 not resolved.&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV id="sasLogWarning2_1688674788999" class="sasWarning"&gt;&lt;FONT color="#FF0000"&gt;WARNING: Apparent symbolic reference STORAGE_CNT_SASAPP2 not resolved.&lt;/FONT&gt;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 06 Jul 2023 20:28:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving/m-p/883824#M349169</guid>
      <dc:creator>kumarsandip975</dc:creator>
      <dc:date>2023-07-06T20:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not resolving.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving/m-p/883829#M349171</link>
      <description>&lt;P&gt;Please, from now on, when there are errors in the log, show us the ENTIRE log for the macro or for the data step. Do not just show us the ERRORs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is the macro scope. This means that macro variables which are assigned values within a macro (in this case, inside macro %macro1) do not exist outside of this macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are generally 3 ways to fix this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Use a &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/mcrolref/p1lhhti7fjxgb1n1fuiubqk11h4d.htm" target="_self"&gt;%GLOBAL&lt;/A&gt; statement inside of %macro1.&lt;/LI&gt;
&lt;LI&gt;Do not assign the macro variables their values inside a macro&lt;/LI&gt;
&lt;LI&gt;Add the &lt;FONT face="courier new,courier"&gt;DATA _NULL_;&lt;/FONT&gt; step into the macro.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding #2, this would work to replace %macro1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let server=SASAPP1;
data _null_;
call symputx("storage_cnt_&amp;amp;server.1",100);
run;
%put &amp;amp;=storage_cnt_&amp;amp;server.1;

/* Repeat with %let serve=SASAPP2 */
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 22:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving/m-p/883829#M349171</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-06T22:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not resolving.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving/m-p/883830#M349172</link>
      <description>&lt;P&gt;Macro variable scope.&lt;/P&gt;
&lt;P&gt;You create the macro variable in a macro, and if it does not exist in the global table before, it will be local to the macro and vanish once the macro terminates. Use the %GLOBAL statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro macro1(server1);
data have_&amp;amp;server1.;
storage_cnt=100;
run;

%global storage_cnt_&amp;amp;server1.;

proc sql noprint;
select storage_cnt into :storage_cnt_&amp;amp;server1. from have_&amp;amp;server1.;
quit;
 
%put storage_cnt_&amp;amp;server1.=&amp;amp;&amp;amp;storage_cnt_&amp;amp;server1.;
%mend macro1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jul 2023 20:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving/m-p/883830#M349172</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-07-06T20:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not resolving.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving/m-p/883851#M349178</link>
      <description>&lt;P&gt;Make sure the macro variables exist so they don't end up being defined as LOCAL to the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also do not use ancient CALL SYMPUT() method unless you really have a need to add leading or trailing spaces into the macro variable.&amp;nbsp; Use CALL SYMPUTX().&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let storage_cnt_SASAPP1=;
%let storage_cnt_SASAPP2=;
%macro1(SASAPP1);
%macro1(SASAPP2);
 
DATA _null_;
total_storage=SUM(&amp;amp;storage_cnt_SASAPP1.,&amp;amp;storage_cnt_SASAPP2.);
call symputX('total_storage',total_storage);
RUN;
%put total_storage=&amp;amp;total_storage.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jul 2023 21:29:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving/m-p/883851#M349178</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-06T21:29:34Z</dc:date>
    </item>
  </channel>
</rss>

