BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nichlas
Calcite | Level 5

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?

Screen Shot 2015-10-25 at 11.02.04 PM.png

(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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

View solution in original post

7 REPLIES 7
PGStats
Opal | Level 21

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
Nichlas
Calcite | Level 5

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!

PGStats
Opal | Level 21

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
Nichlas
Calcite | Level 5

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?

 

 

 

PGStats
Opal | Level 21

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

PG
Nichlas
Calcite | Level 5

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?

 

 

PGStats
Opal | Level 21

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

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
  • 3416 views
  • 1 like
  • 2 in conversation