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:
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.
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 ) ) ) ;
I don't even think that BOTH %sysfunc and %sysevalf are needed : %sysfunc will "host" the computations anyhow.
%LET a = 10 ;
%LET b = 100 ;
%LET log_a_b = %SYSFUNC(LOG(&a/&b)) ;
PS : you can even use the %SYSFUNC to round the result, just add a format as a second argument :
%LET log_a_b = %SYSFUNC(LOG(&a/&b), 10.3) ;