DATA Step, Macro, Functions and more

evaluating logarithm using %sysevalf

Reply
N/A
Posts: 0

evaluating logarithm using %sysevalf

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.
N/A
Posts: 0

Re: evaluating logarithm using %sysevalf

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_ ;
Super Contributor
Posts: 260

Re: evaluating logarithm using %sysevalf

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
N/A
Posts: 0

Re: evaluating logarithm using %sysevalf

Thanks for your responses. %Sysfunc did the trick. I appreciate the help.
Ask a Question
Discussion stats
  • 3 replies
  • 718 views
  • 0 likes
  • 2 in conversation