turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Simplify an algebraic equation

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-04-2018 11:09 AM - last edited on 05-07-2018 08:27 AM by ChrisHemedinger

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"

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to cosimodc

05-04-2018 11:13 AM

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:

@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"

In this video, you learn to create a new variable with Base SAS. You see how to create and modify numeric and character variables using assignment statements in a DATA step. For more tutorials, visit http://support.sas.com/training/tutorial. Learn more about this topic in the SAS® course, SAS ...

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

05-04-2018 01:02 PM

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?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to cosimodc

05-04-2018 01:13 PM

@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?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to cosimodc

05-04-2018 02:56 PM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to cosimodc

05-04-2018 04:24 PM

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).