DATA Step, Macro, Functions and more

Define a numeric macro value with a power function

Accepted Solution Solved
Reply
Contributor
Posts: 73
Accepted Solution

Define a numeric macro value with a power function

Say I want to define a macro variable "num" to be 10 to the negative 2 power (0.01). I do:

 

%let num=%eval(10**(-2));
%put &num.;

 

but I get

 

%put &num.;
SYMBOLGEN: Macro variable NUM resolves to 0
0

 

 What's wrong here? Thanks.


Accepted Solutions
Solution
‎09-07-2017 04:35 PM
Super User
Posts: 19,878

Re: Define a numeric macro value with a power function

Posted in reply to apolitical

To work with floating point numbers use %SYSEVALF().

 

http://blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-syseval...

 The %EVAL function evaluates expressions using integer arithmetic. The %SYSEVALF function evaluates expressions using floating point arithmetic.

 

 

%let num=%sysevalf(10**(-2));
%put &num.;

 

 

View solution in original post


All Replies
Solution
‎09-07-2017 04:35 PM
Super User
Posts: 19,878

Re: Define a numeric macro value with a power function

Posted in reply to apolitical

To work with floating point numbers use %SYSEVALF().

 

http://blogs.sas.com/content/sastraining/2011/09/23/sas-authors-tip-macro-functions-eval-and-syseval...

 The %EVAL function evaluates expressions using integer arithmetic. The %SYSEVALF function evaluates expressions using floating point arithmetic.

 

 

%let num=%sysevalf(10**(-2));
%put &num.;

 

 

Contributor
Posts: 73

Re: Define a numeric macro value with a power function

That works great. Thank you.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 99 views
  • 1 like
  • 2 in conversation