DATA Step, Macro, Functions and more

How to evaluate expression

Reply
Occasional Contributor
Posts: 14

How to evaluate expression

Hi..

I have arithmetic expressions in a character field in a dataset as below...

example:

exp

701*10 ** 6

460*10 ** 6

6.22 * 10**-4

2*10**-3

Am unable to evaluate the expressions and keep them in a numeric variable..Can anyone please help me in this regard..

Thanks

Super User
Posts: 5,441

Re: How to evaluate expression

Posted in reply to kishore415

I suggest that you use the Call Execute routine for this.

Data never sleeps
Super User
Posts: 10,046

Re: How to evaluate expression

Posted in reply to kishore415

How about:

data have;
input exp $20.;
cards;
701*10 ** 6
460*10 ** 6
6.22 * 10**-4
2*10**-3
;
run;
data want;
 set have;
 result=resolve(cats('%sysevalf(',exp,')'));
run;

Ksharp

Super User
Posts: 5,441

Re: How to evaluate expression

Neat!Smiley Happy

Data never sleeps
Super User
Posts: 10,046

Re: How to evaluate expression

LinusH,

You still didn't go to sleep ?

At Sweden , It should be very late.

But At China, It is afternoon.

Ksharp

Smiley Happy

Super User
Posts: 5,441

Re: How to evaluate expression

I had sleep, but is 9 AM in sweden right now, and I 'm back to work!Smiley Happy Thanx for your concern...

Data never sleeps
Valued Guide
Posts: 765

Re: How to evaluate expression

Hi ... great solution.  One extra thing, I think the poster wants a numeric result ...

"Am unable to evaluate the expressions and keep them in a numeric variable"

So maybe ...

data want;

set have;

result=input(resolve(cats('%sysevalf(',exp,')')), 12.);

run;

Super User
Posts: 10,046

Re: How to evaluate expression

You are welcome. In fact , this skill I learned is from this Forum .

Ask a Question
Discussion stats
  • 7 replies
  • 868 views
  • 0 likes
  • 4 in conversation