Date: Fri, 4 Mar 2011 15:06:21 -0500
Reply-To: Clark An <kuhasu@126.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Clark An <kuhasu@126.COM>
Subject: Re: eval the expression in variable
Content-Type: text/plain; charset=ISO-8859-1
can the fcmp and the macro be faster?
A kinda slow~Thx!
413 data mem.a;
414 array a[3]$12. ;
415 a[1]="5";
416 a[2]="*exp(1.7-2)";
417 a[3]="/log(45)";
418 array b[3] ;
419 b[1]=1;
420 b[2]=2;
421 b[3]=3;
422 exp=cat(a[b[1]],a[b[2]],a[b[3]]);
423 do i=1 to 10000;
424 z=myEval(exp);
425 end;
426 run;
NOTE: The data set MEM.A has 1 observations and 9 variables.
NOTE: DATA statement used (Total process time):
real time 8.01 seconds
cpu time 9.07 seconds
At 2011-03-04 23:30:42,"Chang Chung" <chang_y_chung@HOTMAIL.COM> wrote:
>On Thu, 3 Mar 2011 05:11:22 -0500, Clark An <kuhasu@126.COM> wrote:
>
>>d="5+2";
>...
>>is there a function in data step can help to do this?
>>s=function(d);/*s=7*/?
>
>Hi,
>
>Check out this thread on other forum for my %sysevalf() and resolve()
>solution and performance implications compared to other methods:
>http://support.sas.com/forums/thread.jspa?messageID=47081럩
>
>It is possible to write a function exactly like you want using fcmp. It is
>quite slow, though, since it does a data step per the function call:
>
>%macro _myEval;
> %global exp val;
> %let exp = %sysfunc(dequote(&exp));
> data _null_;
> call symputx("val", (&exp), 'g');
> run;
>%mend _myEval;
>
>proc fcmp outlib=work.func.test;
> function myEval(exp $);
> rc = run_macro("_myEval", exp, val);
> return (val);
> endsub;
>quit;
>
>%let cmplib = %sysfunc(getoption(cmplib));
>options cmplib = (work.func &cmplib);
>
> data one;
> length string $40;
> string = "5 + 2"; output;
> string = "log(constant('e')) <> sqrt(2)"; output;
> string = "log(constant('e')) <> sqrt(4)"; output;
> run;
> data two;
> set one;
> result = myEval(string);
> run;
> proc print data=two;
> var result;
> run;
> /* on lst
> Obs result
> 1 7.00000
> 2 1.41421
> 3 2.00000
> */
>
>options cmplib = (&cmplib);
|