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 (June 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 20 Jun 2006 08:15:02 +0100
Reply-To:     Guido T <cymraegerict@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Guido T <cymraegerict@GMAIL.COM>
Subject:      Re: Working on String mathematical expressions
Comments: To: Jagadish <jagadishkr@gmail.com>
In-Reply-To:  <1150779525.748915.40650@b68g2000cwa.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 20/06/06, Jagadish <jagadishkr@gmail.com> wrote: > Hi All, > I have a dataset which has a character variable called var1. Below are > the sample records of this dataset. > > Var1 > 1+2+3 > 3+4+5 > 10+20+100 > > > I want to create a new numeric variable say Var2 which is the result > the string expressions. The final dataset should look like, > > Var1 Var2 > 1+2+3 6 > (3+4)*5 35 > (30-20)+100 110 > > I tried with the below code and it is working fine, > data x; > length var1 $100; > input var1 & $; > call symput('x', var1); > call execute('%let x=%Eval(&x);'); > var2=symget('x'); > cards; > 1+ 2 + 3 > (3 + 4 ) * 5 > (30 - 20) + 100 > ; > run; > > I just wanted to know is there any better way to do this. I mean > without usinng macro variables or is there any SAS function to handle > string math expressions? > > Thanks, > Jagadish > Hi,

I don't know if there is a BETTER way, but using the RESOLVE function seems more straitforward.

data x; length var1 $100 y $20; input var1 & $; y = resolve('%eval('||var1||')'); cards; 1+ 2 + 3 (3 + 4 ) * 5 (30 - 20) + 100 ; run;

Regards ++ Guido


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