DATA Step, Macro, Functions and more

How to get expression value

Reply
N/A
Posts: 0

How to get expression value

I have a dataset with two variables and three observation as following.

Formula($200.) Value(Best20.2)
netpv(0.1, 1,0, 1000)
sin(45)
netpv(0.1,1,0, netpv(0.1,1,0,2000)

How to calculate formula variable and update the result to value variable. Thanks all master-hand first!
Super Contributor
Posts: 359

Re: How to get expression value

Posted in reply to deleted_user
is this what you mean?

data _null_;
set xxx end = eof;
if _n_ = 1 then
call execute('data new; set xxx;');
call execute('if formula = "' || formula ||'" then value = ' ||formula || ';');
if eof then call execute('run;');
run;
N/A
Posts: 0

Re: How to get expression value

You are my God, thank you very much!
Respected Advisor
Posts: 3,799

Re: How to get expression value

Posted in reply to deleted_user
This will be slow and it doesn't handle nested functions.

[pre]
data results;
input formula $40.;
value = input(resolve(cats('%sysfunc(',formula,')')),f8.);
cards;
netpv(0.1, 1,0, 1000)
sin(45)
netpv(0.1,1,0,2000)
;;;;
run;
proc print;
run;
[/pre]
Ask a Question
Discussion stats
  • 3 replies
  • 139 views
  • 0 likes
  • 3 in conversation