<?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: Macro Variable Resolution Problenm in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Resolution-Problenm/m-p/857387#M338796</link>
    <description>&lt;P&gt;You need to add more &amp;amp; to do that type of reference by name.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you have now,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;amp;_test._num&lt;/FONT&gt;, will evaluate to &lt;FONT face="courier new,courier"&gt;count_num&lt;/FONT&gt; which is NOT a number.&lt;/P&gt;
&lt;P&gt;If you add two extra &amp;amp; at the front then it will work.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;amp;&amp;amp;&amp;amp;_test._num&lt;/FONT&gt;&amp;nbsp;will evaluate to &lt;FONT face="courier new,courier"&gt;&amp;amp;count_num&amp;nbsp;&lt;/FONT&gt;which will evaluate to 19.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no need for the macro quoting (it is just complicating things).&amp;nbsp; There is no way your third result from the IFN() call will ever happen.&amp;nbsp; The result of a boolean expression like X eq B is always going to be either TRUE (1) or FALSE (0). It can never be missing. So just use %EVAL(), or %SYSEVALF() to support non-integer comparison, to create your flag.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET _L0_year = 23;
%LET _test = count;

%let &amp;amp;_test._num = ;
proc sql noprint;
select count(distinct name) into :&amp;amp;_test._num trimmed
  from sashelp.class
;
quit;

%LET flag_ok = %sysevalf(&amp;amp;_L0_year. - &amp;amp;&amp;amp;&amp;amp;_test._num eq 4);

%put &amp;amp;=_L0_year &amp;amp;=_test -&amp;gt; &amp;amp;&amp;amp;&amp;amp;_test._num &amp;amp;=flag_ok ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Feb 2023 15:42:17 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-02-06T15:42:17Z</dc:date>
    <item>
      <title>Macro Variable Resolution Problenm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Resolution-Problenm/m-p/857375#M338794</link>
      <description>&lt;P&gt;Hey Everyone,&lt;/P&gt;
&lt;P&gt;I got stuck with a piece of code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET _L0_year = 23;
%LET _test = count;

proc sql noprint;
select count(distinct name) into: %nrquote(&amp;amp;_test._num) trimmed
from sashelp.class;
quit;

%PUT &amp;amp;=count_num;

%LET flag_ok = %sysfunc(ifn(&amp;amp;_L0_year. - %unquote(&amp;amp;_test._num) eq 4,1,0,-1));
%PUT &amp;amp;=flag_ok;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I get this error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: Argument 1 to function IFN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list.  Execution of %SYSCALL statement or %SYSFUNC 
       or %QSYSFUNC function reference is terminated.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Obviously, I have not yet found the correct macro function in order to resolve the macro variable "count_num" to its value of "19" since the value of the macro variable "&lt;CODE class=" language-sas"&gt;flag_ok &lt;/CODE&gt;" should be 1, as the condtion evaluates to true (23 - 19 = 4).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anybody have an idea?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2023 14:52:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Resolution-Problenm/m-p/857375#M338794</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2023-02-06T14:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable Resolution Problenm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Resolution-Problenm/m-p/857380#M338795</link>
      <description>&lt;P&gt;Naturally, it would help if we knew what this piece of code is supposed to be doing (rather than knowing that &amp;amp;FLAG_OK should be equal to 1). Can you tell us what it is supposed to be doing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, without such information, all I can do is guess that maybe you want this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET flag_ok = %sysfunc(ifn(&amp;amp;_L0_year. - &amp;amp;&amp;amp;&amp;amp;_test._num eq 4,1,0,-1));
%PUT &amp;amp;=flag_ok;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or maybe you don't want this. Maybe this just works for the one case but does bad things for other cases. You tell us.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2023 15:07:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Resolution-Problenm/m-p/857380#M338795</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-06T15:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable Resolution Problenm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Resolution-Problenm/m-p/857387#M338796</link>
      <description>&lt;P&gt;You need to add more &amp;amp; to do that type of reference by name.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you have now,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;amp;_test._num&lt;/FONT&gt;, will evaluate to &lt;FONT face="courier new,courier"&gt;count_num&lt;/FONT&gt; which is NOT a number.&lt;/P&gt;
&lt;P&gt;If you add two extra &amp;amp; at the front then it will work.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;amp;&amp;amp;&amp;amp;_test._num&lt;/FONT&gt;&amp;nbsp;will evaluate to &lt;FONT face="courier new,courier"&gt;&amp;amp;count_num&amp;nbsp;&lt;/FONT&gt;which will evaluate to 19.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no need for the macro quoting (it is just complicating things).&amp;nbsp; There is no way your third result from the IFN() call will ever happen.&amp;nbsp; The result of a boolean expression like X eq B is always going to be either TRUE (1) or FALSE (0). It can never be missing. So just use %EVAL(), or %SYSEVALF() to support non-integer comparison, to create your flag.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET _L0_year = 23;
%LET _test = count;

%let &amp;amp;_test._num = ;
proc sql noprint;
select count(distinct name) into :&amp;amp;_test._num trimmed
  from sashelp.class
;
quit;

%LET flag_ok = %sysevalf(&amp;amp;_L0_year. - &amp;amp;&amp;amp;&amp;amp;_test._num eq 4);

%put &amp;amp;=_L0_year &amp;amp;=_test -&amp;gt; &amp;amp;&amp;amp;&amp;amp;_test._num &amp;amp;=flag_ok ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2023 15:42:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Resolution-Problenm/m-p/857387#M338796</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-06T15:42:17Z</dc:date>
    </item>
  </channel>
</rss>

