<?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: How to call a macro variable that is created within another macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-marco-variable-that-is-created-within-another/m-p/647200#M193661</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;%MACRO&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;C(VAR,COUNT_VAR,FILTER);&lt;/P&gt;
&lt;P&gt;PROC SQL ;&lt;/P&gt;
&lt;P&gt;SELECT COUNT(&amp;amp;VAR) INTO: &amp;amp;COUNT_VAR&lt;/P&gt;
&lt;P&gt;FROM table2&lt;/P&gt;
&lt;P&gt;WHERE &amp;amp;FILTER;&lt;/P&gt;
&lt;P&gt;QUIT;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%MEND&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;C&lt;/EM&gt;&lt;/STRONG&gt;(Unsuccessful_item, COUNT_U,Unsuccessful_item EQ "Yes");&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;C&lt;/EM&gt;&lt;/STRONG&gt;(Late_item,COUNT_L,Late_item EQ "Yes");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%PUT &amp;amp;COUNT_U &amp;amp;COUNT_L;&lt;/P&gt;
&lt;P&gt;WARNING: Apparent symbolic reference COUNT_U not resolved.&lt;/P&gt;
&lt;P&gt;WARNING: Apparent symbolic reference COUNT_L not resolved.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro scoping. Since &amp;amp;COUNT_U is created inside the macro %C, it has value inside the macro, but does not exist outside %C, and so your %PUT is referring to a macro variable that does not exist. You can either make &amp;amp;COUNT_U and &amp;amp;COUNT_L global using the %global command, or use the %PUT inside the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO C(VAR,COUNT_VAR,FILTER);
%global &amp;amp;count_var;
/* The rest of your macro goes here */
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 May 2020 19:46:01 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-05-12T19:46:01Z</dc:date>
    <item>
      <title>How to call a marco variable that is created within another macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-marco-variable-that-is-created-within-another/m-p/647192#M193659</link>
      <description>&lt;P&gt;I need to call two macro variables which are created within another macro. However, I got the following warning message saying Apparent symbolic reference not resovled. &amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to do is to create a macro variable for the total count of the item and put the number of count in the log.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%MACRO&lt;/STRONG&gt; C(VAR,COUNT_VAR,FILTER);&lt;/P&gt;&lt;P&gt;PROC SQL ;&lt;/P&gt;&lt;P&gt;SELECT COUNT(&amp;amp;VAR) INTO: &amp;amp;COUNT_VAR&lt;/P&gt;&lt;P&gt;FROM table2&lt;/P&gt;&lt;P&gt;WHERE &amp;amp;FILTER;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%MEND&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;C&lt;/EM&gt;&lt;/STRONG&gt;(Unsuccessful_item, COUNT_U,Unsuccessful_item EQ "Yes");&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;C&lt;/EM&gt;&lt;/STRONG&gt;(Late_item,COUNT_L,Late_item EQ "Yes");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;COUNT_U &amp;amp;COUNT_L;&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference COUNT_U not resolved.&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference COUNT_L not resolved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I do this in two separate steps, I am able to run through. However, in real work situation, I need to do this in macro, can anyone advice. Thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;SQL&lt;/STRONG&gt; ;&lt;/P&gt;&lt;P&gt;SELECT COUNT(Unsuccessful_item) INTO: COUNT_U&lt;/P&gt;&lt;P&gt;FROM table2&lt;/P&gt;&lt;P&gt;WHERE Unsuccessful_item EQ "Yes";&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;QUIT&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;SQL&lt;/STRONG&gt; ;&lt;/P&gt;&lt;P&gt;SELECT COUNT(Late_item) INTO: COUNT_L&lt;/P&gt;&lt;P&gt;FROM table2&lt;/P&gt;&lt;P&gt;WHERE Late_item EQ "Yes";&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;QUIT&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;COUNT_U &amp;amp;COUNT_L;&lt;/P&gt;&lt;P&gt;38&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %PUT &amp;amp;COUNT_U &amp;amp;COUNT_L;&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable COUNT_U resolves to&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable COUNT_L resolves to&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 25&lt;/P&gt;&lt;P&gt;13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 25&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 18:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-marco-variable-that-is-created-within-another/m-p/647192#M193659</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2020-05-12T18:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a marco variable that is created within another macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-marco-variable-that-is-created-within-another/m-p/647196#M193660</link>
      <description>&lt;P&gt;Without details of how you expect to use the variables there aren't a lot of options.&lt;/P&gt;
&lt;P&gt;The basic approach if you need to use a macro variable created out of the current scope is often to make the macro variable a global value. That would be done with the %global statement :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%global sometext;&lt;/P&gt;
&lt;P&gt;would create a macro variable sometext that is available everywhere in the current session.&lt;/P&gt;
&lt;P&gt;It will be up to you to make sure that you don't reuse macro variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is not a trivial subject. You will want to look up scope of macro variables in documentation.&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 18:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-marco-variable-that-is-created-within-another/m-p/647196#M193660</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-12T18:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a macro variable that is created within another macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-marco-variable-that-is-created-within-another/m-p/647200#M193661</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;%MACRO&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;C(VAR,COUNT_VAR,FILTER);&lt;/P&gt;
&lt;P&gt;PROC SQL ;&lt;/P&gt;
&lt;P&gt;SELECT COUNT(&amp;amp;VAR) INTO: &amp;amp;COUNT_VAR&lt;/P&gt;
&lt;P&gt;FROM table2&lt;/P&gt;
&lt;P&gt;WHERE &amp;amp;FILTER;&lt;/P&gt;
&lt;P&gt;QUIT;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%MEND&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;C&lt;/EM&gt;&lt;/STRONG&gt;(Unsuccessful_item, COUNT_U,Unsuccessful_item EQ "Yes");&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;C&lt;/EM&gt;&lt;/STRONG&gt;(Late_item,COUNT_L,Late_item EQ "Yes");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%PUT &amp;amp;COUNT_U &amp;amp;COUNT_L;&lt;/P&gt;
&lt;P&gt;WARNING: Apparent symbolic reference COUNT_U not resolved.&lt;/P&gt;
&lt;P&gt;WARNING: Apparent symbolic reference COUNT_L not resolved.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro scoping. Since &amp;amp;COUNT_U is created inside the macro %C, it has value inside the macro, but does not exist outside %C, and so your %PUT is referring to a macro variable that does not exist. You can either make &amp;amp;COUNT_U and &amp;amp;COUNT_L global using the %global command, or use the %PUT inside the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO C(VAR,COUNT_VAR,FILTER);
%global &amp;amp;count_var;
/* The rest of your macro goes here */
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 19:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-marco-variable-that-is-created-within-another/m-p/647200#M193661</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-12T19:46:01Z</dc:date>
    </item>
  </channel>
</rss>

