BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I'm writing a SAS macro which includes a proc sql. Within the proc sql, I need to take a logarithm. I tried doing so using:

%let DDenom=%sysevalf(log(&ProbBad/&ProbGood));

and receive the following error when the macro runs:

'A character operand was found in the %EVAL function or %IF condition when a numeric operand is required.'

What am I doing wrong? I realize that %EVAL only works with integer values and can return this message when asked to do floating-point calculations, but I thought that %sysevalf could handle this kind of calculation. Any help would be greatly appreciated.
3 REPLIES 3
deleted_user
Not applicable
The error is coming from the fact that you are trying to use a data step fuction in the macro facility without also using %SysFunc. %SysEvalF sees that and cant make out what to do with it and throws the error you are seeing.

Try this instead.

%Let A = 10 ;
%Let B = 100 ;
%Let C = %SysEvalF( %SysFunc( Log( &A / &B ) ) ) ;

%Put _User_ ;
Olivier
Pyrite | Level 9
I don't even think that BOTH %sysfunc and %sysevalf are needed : %sysfunc will "host" the computations anyhow.
[pre]
%LET a = 10 ;
%LET b = 100 ;
%LET log_a_b = %SYSFUNC(LOG(&a/&b)) ;
[/pre]
PS : you can even use the %SYSFUNC to round the result, just add a format as a second argument :
[pre]
%LET log_a_b = %SYSFUNC(LOG(&a/&b), 10.3) ;
[/pre]
Regards.
Olivier
deleted_user
Not applicable
Thanks for your responses. %Sysfunc did the trick. I appreciate the help.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 3355 views
  • 1 like
  • 2 in conversation