BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
FK1
Lapis Lazuli | Level 10 FK1
Lapis Lazuli | Level 10

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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 ;

 

 

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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.

 

 

--
Paige Miller
Tom
Super User Tom
Super User

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 ;

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 340 views
  • 2 likes
  • 3 in conversation