SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
cosimodc
Calcite | Level 5

Hi All,

is possible to simplify algebric equation?

I have a character variable with a equation:

"x+2+5+2x+3"

I would create a new variable

"3x+10"

 

 

5 REPLIES 5
Reeza
Super User

What is the question you need help with then?

 

You can find basic tutorials here:

http://video.sas.com/category/videos/sas-analytics-u

 

Including this one on creating new variables:

http://video.sas.com/detail/videos/sas-analytics-u/video/4573023399001/creating-a-new-column-in-sas?...

 


@cosimodc wrote:

Hi All,

is possible to simplify algebric equation?

I have a character variable with a equation:

"x+2+5+2x+3"

I would create a new variable

"3x+10"

 

 


 

 

cosimodc
Calcite | Level 5

I want to minimize length a variable which contains a equation.

For example:

data test;

a=x+3x+5x+10*2+4x+10x+x**2+20x;

run;

 

data new;

b=x**2+43x+20;

run;

 

Is possible?

 

ballardw
Super User

@cosimodc wrote:

I want to minimize length a variable which contains a equation.

For example:

data test;

a=x+3x+5x+10*2+4x+10x+x**2+20x;

run;

 

data new;

b=x**2+43x+20;

run;

 

Is possible?

 


Possible yes.

How much experience to you have writing compilers that parse code? Which is in effect what you are requesting. You would have to specify exactly every type of function and the reduction rule and I am afraid that  introducing () in to the equations means the logic is going to be extremely complex.

Consider

((x+3x+5x+10)*2+4x+10x+x)**2+20x

 

How are you using these things such that the length is a critical issue?

Reeza
Super User

I probably woudn't use SAS for that. Wolfram Alpha can do that and I *think* it has an API call, but it may be a paid service.

Rick_SAS
SAS Super FREQ

As someone mentioned, SAS is primarily a numerical language. If you are looking for symbolic computations such as simplifying an algebraic expression, Wolfram Alpha or other symbolic software would be a better choice. 

 

If you want to find the value of x that minimizes or maximizes an expression, then you are solving an optimization problem, and SAS has many ways to numerically optimize equations, including PROC NLIN and NLMIXED (SAS/STAT), PROC IML (SAS/IML), and PROC OPTMODEL (SAS/OR). 

 

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1483 views
  • 1 like
  • 4 in conversation