LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2011, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 4 Mar 2011 10:30:42 -0500
Reply-To:     Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject:      Re: eval the expression in variable
Comments: To: Clark An <kuhasu@126.COM>

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&#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);


Back to: Top of message | Previous page | Main SAS-L page