Hey Everyone,
I got stuck with a piece of code:
%LET _L0_year = 23;
%LET _test = count;
proc sql noprint;
select count(distinct name) into: %nrquote(&_test._num) trimmed
from sashelp.class;
quit;
%PUT &=count_num;
%LET flag_ok = %sysfunc(ifn(&_L0_year. - %unquote(&_test._num) eq 4,1,0,-1));
%PUT &=flag_ok;
I get this error:
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.
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 "flag_ok
" should be 1, as the condtion evaluates to true (23 - 19 = 4).
Does anybody have an idea?
You need to add more & to do that type of reference by name.
What you have now, &_test._num, will evaluate to count_num which is NOT a number.
If you add two extra & at the front then it will work.
&&&_test._num will evaluate to &count_num which will evaluate to 19.
There is no need for the macro quoting (it is just complicating things). There is no way your third result from the IFN() call will ever happen. 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.
%LET _L0_year = 23;
%LET _test = count;
%let &_test._num = ;
proc sql noprint;
select count(distinct name) into :&_test._num trimmed
from sashelp.class
;
quit;
%LET flag_ok = %sysevalf(&_L0_year. - &&&_test._num eq 4);
%put &=_L0_year &=_test -> &&&_test._num &=flag_ok ;
Naturally, it would help if we knew what this piece of code is supposed to be doing (rather than knowing that &FLAG_OK should be equal to 1). Can you tell us what it is supposed to be doing?
Anyway, without such information, all I can do is guess that maybe you want this:
%LET flag_ok = %sysfunc(ifn(&_L0_year. - &&&_test._num eq 4,1,0,-1));
%PUT &=flag_ok;
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.
You need to add more & to do that type of reference by name.
What you have now, &_test._num, will evaluate to count_num which is NOT a number.
If you add two extra & at the front then it will work.
&&&_test._num will evaluate to &count_num which will evaluate to 19.
There is no need for the macro quoting (it is just complicating things). There is no way your third result from the IFN() call will ever happen. 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.
%LET _L0_year = 23;
%LET _test = count;
%let &_test._num = ;
proc sql noprint;
select count(distinct name) into :&_test._num trimmed
from sashelp.class
;
quit;
%LET flag_ok = %sysevalf(&_L0_year. - &&&_test._num eq 4);
%put &=_L0_year &=_test -> &&&_test._num &=flag_ok ;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.