p***r 发帖数: 920 | 1 data set TEMP is like this
A B Formula
----------------------------
1 2 A*B
.....
wanna call the value in formula column as an string calculate the value.
such as
data TEMP2;
set TEMP;
cost= ????; *Here is what I need do input according to formula A*B;
run;
Any one can help? |
d*******o 发帖数: 493 | 2 --------------Macro-------------
regular expression --> PROC FCMP
--------------Macro------------- |
p***r 发帖数: 920 | 3 I don't get it
【在 d*******o 的大作中提到】 : --------------Macro------------- : regular expression --> PROC FCMP : --------------Macro-------------
|
D******n 发帖数: 2836 | 4 if u just have limited formula ,write "if and then"s to do it.
【在 p***r 的大作中提到】 : data set TEMP is like this : A B Formula : ---------------------------- : 1 2 A*B : ..... : wanna call the value in formula column as an string calculate the value. : such as : data TEMP2; : set TEMP; : cost= ????; *Here is what I need do input according to formula A*B;
|
p***r 发帖数: 920 | 5 I can do that way, but what if there is 100 formulas, just curious how to
output as neither character nor numeric value but as string executable.
【在 D******n 的大作中提到】 : if u just have limited formula ,write "if and then"s to do it.
|
s*********e 发帖数: 1051 | 6 i have written the similar code before but am just curious to see other more
elegant solution :-) |
A*******s 发帖数: 3942 | 7 data test;
input A B formula $;
cards;
23 12 A*B
75 2 A-B
6 7843 A/B
74 5 A**B
;
run;
data _null_;
set test end=eof;
if _N_=1 then call execute("data test2;");
call execute("i="||_N_||"; set test point=i; result="||formula||";
output;");
if eof then call execute("stop; drop i; run;");
run;
|
s*********e 发帖数: 1051 | 8 this is better than mine. i used macro.
【在 A*******s 的大作中提到】 : data test; : input A B formula $; : cards; : 23 12 A*B : 75 2 A-B : 6 7843 A/B : 74 5 A**B : ; : run; : data _null_;
|
D******n 发帖数: 2836 | 9 This trick is actually using Macro facility in the background.
【在 s*********e 的大作中提到】 : this is better than mine. i used macro.
|
D******n 发帖数: 2836 | 10 this seems faster, but only applicable when the number of vars are small.
data _null_;
set test end=eof;
if _N_=1 then call execute("data test3;");
call execute("A="||A||";B="||B||";result="||formula||";output;");
if eof then call execute(" run;");
run;
【在 A*******s 的大作中提到】 : data test; : input A B formula $; : cards; : 23 12 A*B : 75 2 A-B : 6 7843 A/B : 74 5 A**B : ; : run; : data _null_;
|
l******r 发帖数: 12 | 11 A simple one
data have;
input a b formula $;
datalines;
2 3 a*b
5 56 a-b
;
run;
data _null_;
set have;
call symputx("formula",formula);
run;
data need;
set have;
d=&formula.;
run; |
p***r 发帖数: 920 | 12 This one not work, but actually provide a very good hint to what I want.
Thanks
【在 l******r 的大作中提到】 : A simple one : data have; : input a b formula $; : datalines; : 2 3 a*b : 5 56 a-b : ; : run; : data _null_; : set have;
|