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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3062 views
  • 1 like
  • 2 in conversation