Date: Mon, 19 Jun 2006 21:58:45 -0700
Reply-To: Jagadish <jagadishkr@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jagadish <jagadishkr@GMAIL.COM>
Organization: http://groups.google.com
Subject: Working on String mathematical expressions
Content-Type: text/plain; charset="iso-8859-1"
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