BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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!
3 REPLIES 3
Flip
Fluorite | Level 6
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;
deleted_user
Not applicable
You are my God, thank you very much!
data_null__
Jade | Level 19
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]

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1267 views
  • 0 likes
  • 3 in conversation