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
- /
- General Programming
- /
- Solve Equation

Topic Options

- Subscribe to 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
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-25-2015 11:05 PM - edited 10-25-2015 11:10 PM

I'd like to solve unknown y in the eqaution given x (here is 1) and n (here is 10), and I wonder where's the bug?

(Please note that in the second line y=0.5 doesn't mean y is 0.5 for the equation, rather, it merely stipulates that the program search for the solution starting from y=0.5).

data goal; y=0.5;x=1;n=10; run; proc model data=goal; /*Compute the sum term*/ sum=0; do i=1 to n sum=sum+1/y**i; end; /*Equation to be solved, with unknown y*/ x=sum; solve y/out=roots; run; proc print; run;

Accepted Solutions

Solution

10-27-2015
12:54 AM

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

10-26-2015 09:54 PM

**satisfy=** should name the left side of an equation, thus identifying that equation as the one to be satisfied.

**eq = f(x, y, z);**

**solve z satisfy=eq / ...;**

finds the root of **f(X,Y,z) - eq** where **X** and **Y** are values given in your dataset.

PG

All Replies

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

10-25-2015 11:36 PM

Try with proper syntax:

```
data goal;
y=0.5; x=1; n=10;
run;
proc model plots=none;
sum = 0;
do i = 1 to n;
sum = sum + 1/y**i;
end;
x = sum;
solve y satisfy=x / data=goal out=mysoln;
run;
proc print data=mysoln; run;
```

PG

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

10-26-2015 08:23 AM

Many thanks. Could you also explain a bit about:

1.

`plots=none`

What does this sentence mean? Is it something I have to write (I guess it's about graphing, right?)?

2.

`satisfy=x`

Since x and n are both known, why can we just write x to be satisfied?

Thanks again!

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

10-26-2015 11:00 AM

Disclaimer: I don't use proc model often and only understand parts of it.

**plots=none** prevents default plotting by the procedure (often takes a lot longer to execute than the problem solving itself)

**x=sum** defines the model equation, **solve y satisfy=x** means find **y** that satisfies the equation.

PG

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

10-26-2015 04:02 PM

But I wonder why n=10 is not treated as something we need to guarantee/satisfy?

Also, it seems that if I don't write **satisfy=x** in your sample code, the code still works and is able to find the solution. But interestingly, there's an error in th log: The following solve variables do not appear in any of the equations to be solve (although it doesn't prevent me from reaching the the solution of the equation).

Additionaly, I tried a more complicated example which has several known variables,

data goal;

p=90;yield=0.08;coupon=0.07;T=5;par=100;

run;

proc model;

sum = 0;

do i = 1 to T;

sum = sum + par*coupon/(1+yield)**i;

end;

sum=sum+par/(1+yield)**5;

p = sum;

solve yield / data=goal out=bondprice;

run;

proc print data=bondprice; run;

The variable I'd like to compute is the true yield of bond, I used **solve yield** but this time I didn't get correct solution for yield, instead I got the appropriate p to make this equation hold.

So my question is, in general, to solve for a single unknown in an equation with several known varibles, what's the correct code?

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

10-26-2015 05:58 PM

Adding SATISFY=p raises the ambiguity about which equation you are trying to solve and finds the *true yield* = 0.096119

PG

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

10-26-2015 09:28 PM

So if I denote the line above the "solve yield..." line as equation line (in our case is "p=sum"), then any variables appearing in this line are recognized as known variables and should be added to the sentence "satisfy=...", right?

Solution

10-27-2015
12:54 AM

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

10-26-2015 09:54 PM

**satisfy=** should name the left side of an equation, thus identifying that equation as the one to be satisfied.

**eq = f(x, y, z);**

**solve z satisfy=eq / ...;**

finds the root of **f(X,Y,z) - eq** where **X** and **Y** are values given in your dataset.

PG