turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- evaluating logarithm using %sysevalf

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-25-2008 10:13 AM

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.

%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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-25-2008 05:27 PM

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_ ;

Try this instead.

%Let A = 10 ;

%Let B = 100 ;

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

%Put _User_ ;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-26-2008 05:36 AM

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

[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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-26-2008 11:08 AM

Thanks for your responses. %Sysfunc did the trick. I appreciate the help.