- proc fcmp outlib=work.funcs.test;
- function strparser(expression $) $ 100;
- length x y $100;
- x = ''; y = ''; m = 0; n = 0;
- l = length(expression);
- do i = 1 to l;
- b = substr(expression, i, 1);
- if prxmatch('/[a-z]/', b) then do;
- y = cats(y, b);
- end;
- else if b='(' then do;
- if y ne '' then do;
- y = cats('%sysfunc(', cats(y, b));
- x = cats(x, y);
- y = '';
- m = m+1;
- end ;
- n = n + 1;
- end;
- else if b = ')' then do;
- n = n - 1;
- if m = n+1 then do;
- x = cats(x, cats(cats(ifc(y='','',cats('&',y)),b),')'));
- y = '';
- m = m - 1;
- end;
- end;
- else do;
- x = cats(x, cats(ifc(y='','',cats('&',y)),b));
- y='';
- end;
- end;
- x = cats(x, ifc(y='','',cats('&',y)));
- return (x);
- endsub;
- run;
- options cmplib=work.funcs;
- data _null_;
- length x $ 1000;
- input a b c d t:$100.;
- array y _numeric_;
- do over y;
- call symput(lowcase(vname(y)),y);
- end;
- x = cats('%sysevalf(',strparser(compress(lowcase(t))),')');
- call symput('formula', x);
- result = input(resolve('&formula'),best.);
- put result;
- cards;
- 1 2 3 4 a+cos(sum(c,exp(d+log(b))))
- 10 15 20 25 sin(a)+cos(sum(b,exp(c+log(d))))
- 5 6 7 8 b/d
- ;
- run;