<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Solve Equation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231761#M268096</link>
    <description>&lt;P&gt;So if I denote&amp;nbsp;the line above the "solve yield..." line as equation line (in our case is "p=sum"), then any variables appearing in&amp;nbsp;this line are recognized as known variables and should be added to the sentence "satisfy=...", right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Oct 2015 01:28:43 GMT</pubDate>
    <dc:creator>Nichlas</dc:creator>
    <dc:date>2015-10-27T01:28:43Z</dc:date>
    <item>
      <title>Solve Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231581#M268089</link>
      <description>&lt;P&gt;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?&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/640i92D3E4BB372FF38F/image-size/small?v=mpbl-1&amp;amp;px=-1" border="0" alt="Screen Shot 2015-10-25 at 11.02.04 PM.png" title="Screen Shot 2015-10-25 at 11.02.04 PM.png" width="100" height="64" /&gt;&lt;/P&gt;
&lt;P&gt;(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&amp;nbsp;the program search for the solution&amp;nbsp;starting from y=0.5).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 03:10:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231581#M268089</guid>
      <dc:creator>Nichlas</dc:creator>
      <dc:date>2015-10-26T03:10:24Z</dc:date>
    </item>
    <item>
      <title>Re: Solve Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231584#M268090</link>
      <description>&lt;P&gt;Try with proper syntax:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
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;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Oct 2015 03:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231584#M268090</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-10-26T03:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Solve Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231612#M268092</link>
      <description>&lt;P&gt;Many thanks. Could you also explain a bit about:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp;&lt;/P&gt;
&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt;plots&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;none&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What does this sentence mean? Is it something I have to write (I guess it's about graphing, right?)?&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp;&lt;/P&gt;
&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt;satisfy&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;x&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Since x and n are both known, why can we&amp;nbsp;just write x to be satisfied?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 12:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231612#M268092</guid>
      <dc:creator>Nichlas</dc:creator>
      <dc:date>2015-10-26T12:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Solve Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231641#M268093</link>
      <description>&lt;P&gt;Disclaimer: I don't use proc model often and only understand parts of it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;plots=none&lt;/STRONG&gt; prevents default plotting by the procedure (often takes a lot longer to execute than the problem solving itself)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;x=sum&lt;/STRONG&gt; defines the model equation, &lt;STRONG&gt;solve y satisfy=x&lt;/STRONG&gt; means find &lt;STRONG&gt;y&lt;/STRONG&gt; that satisfies the equation.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 15:00:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231641#M268093</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-10-26T15:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: Solve Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231726#M268094</link>
      <description>&lt;P&gt;But I wonder why n=10 is not treated as something we need to guarantee/satisfy?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, it seems that if I don't write &lt;STRONG&gt;satisfy=x&lt;/STRONG&gt;&amp;nbsp;in your sample code, the code still works and is able to find the solution. But interestingly, there's an error in th log&lt;SPAN&gt;: 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).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Additionaly, I tried a more complicated example which has several known variables,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data goal;&lt;BR /&gt;p=90;yield=0.08;coupon=0.07;T=5;par=100;&lt;BR /&gt;run;&lt;BR /&gt;proc model;&lt;BR /&gt;sum = 0;&lt;BR /&gt;do i = 1 to T;&lt;BR /&gt; sum = sum + par*coupon/(1+yield)**i;&lt;BR /&gt;end;&lt;BR /&gt;sum=sum+par/(1+yield)**5;&lt;BR /&gt;p = sum;&lt;BR /&gt;solve yield / data=goal out=bondprice;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=bondprice; run;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;The variable I'd like to compute is the true yield of bond, I used &lt;STRONG&gt;solve yield&lt;/STRONG&gt;&amp;nbsp; but this time I didn't get correct solution for yield, instead I got the appropriate p to make this equation hold.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So my question is, in general, to solve for a single unknown in an equation with several known varibles, what's the correct code?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 20:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231726#M268094</guid>
      <dc:creator>Nichlas</dc:creator>
      <dc:date>2015-10-26T20:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Solve Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231736#M268095</link>
      <description>&lt;P&gt;Adding SATISFY=p raises the ambiguity about which equation you are trying to solve and finds the &lt;EM&gt;true yield&lt;/EM&gt; =&amp;nbsp; 0.096119&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 21:58:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231736#M268095</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-10-26T21:58:18Z</dc:date>
    </item>
    <item>
      <title>Re: Solve Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231761#M268096</link>
      <description>&lt;P&gt;So if I denote&amp;nbsp;the line above the "solve yield..." line as equation line (in our case is "p=sum"), then any variables appearing in&amp;nbsp;this line are recognized as known variables and should be added to the sentence "satisfy=...", right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2015 01:28:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231761#M268096</guid>
      <dc:creator>Nichlas</dc:creator>
      <dc:date>2015-10-27T01:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Solve Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231763#M268097</link>
      <description>&lt;P&gt;&lt;STRONG&gt;satisfy=&lt;/STRONG&gt; should name the left side of an equation, thus identifying that equation as the one to be satisfied.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;eq = f(x, y, z);&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;solve z satisfy=eq / ...;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;finds the root of &lt;STRONG&gt;f(X,Y,z) - eq&lt;/STRONG&gt; where &lt;STRONG&gt;X&lt;/STRONG&gt; and &lt;STRONG&gt;Y&lt;/STRONG&gt; are values given in your dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2015 01:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/231763#M268097</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-10-27T01:54:51Z</dc:date>
    </item>
  </channel>
</rss>

