BookmarkSubscribeRSS Feed
kishore415
Calcite | Level 5

Hi..

I have arithmetic expressions in a character field in a dataset as below...

example:

exp

701*10 ** 6

460*10 ** 6

6.22 * 10**-4

2*10**-3

Am unable to evaluate the expressions and keep them in a numeric variable..Can anyone please help me in this regard..

Thanks

7 REPLIES 7
LinusH
Tourmaline | Level 20

I suggest that you use the Call Execute routine for this.

Data never sleeps
Ksharp
Super User

How about:

data have;
input exp $20.;
cards;
701*10 ** 6
460*10 ** 6
6.22 * 10**-4
2*10**-3
;
run;
data want;
 set have;
 result=resolve(cats('%sysevalf(',exp,')'));
run;

Ksharp

LinusH
Tourmaline | Level 20

Neat!Smiley Happy

Data never sleeps
Ksharp
Super User

LinusH,

You still didn't go to sleep ?

At Sweden , It should be very late.

But At China, It is afternoon.

Ksharp

Smiley Happy

LinusH
Tourmaline | Level 20

I had sleep, but is 9 AM in sweden right now, and I 'm back to work!Smiley Happy Thanx for your concern...

Data never sleeps
MikeZdeb
Rhodochrosite | Level 12

Hi ... great solution.  One extra thing, I think the poster wants a numeric result ...

"Am unable to evaluate the expressions and keep them in a numeric variable"

So maybe ...

data want;

set have;

result=input(resolve(cats('%sysevalf(',exp,')')), 12.);

run;

Ksharp
Super User

You are welcome. In fact , this skill I learned is from this Forum .

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 2686 views
  • 0 likes
  • 4 in conversation