## Solve Equation

Solved
Occasional Contributor
Posts: 6

# Solve Equation

[ Edited ]

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
Posts: 5,532

## Re: Solve Equation

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
Posts: 5,532

## Re: Solve Equation

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
Occasional Contributor
Posts: 6

## Re: Solve Equation

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!

Posts: 5,532

## Re: Solve Equation

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
Occasional Contributor
Posts: 6

## Re: Solve Equation

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?

Posts: 5,532

## Re: Solve Equation

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

PG
Occasional Contributor
Posts: 6

## Re: Solve Equation

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
Posts: 5,532

## Re: Solve Equation

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
🔒 This topic is solved and locked.