<?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 -Cost of capital in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/765820#M242607</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/39704"&gt;@MAC1430&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you can use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p1xoknqns865t7n1wehj6xarwhdb.htm" target="_blank" rel="noopener"&gt;SOLVE function&lt;/A&gt; in PROC FCMP:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Define function DISCRATE */

proc fcmp outlib=work.funcs.test;
function rhs(t, B[*], a, g, e[*], c);
  s=B[t];
  do tau=1 to 5;
    s = s + a*e[t+tau]/(1+g+c)**tau;
  end;
  s = s + a*e[t+5]*(1+g)/(c*(1+g+c)**5);
  return(s);
endfunc;
function discrate(t, P[*], B[*], a, g, e[*]);
  r=g+solve("RHS", {.}, P[t], t, B, a, g, e, .);
  return(r);
endfunc;
run;

/* Make function available */

options cmplib=work.funcs;

/* Apply function DISCRATE to arbitrary sample data */

data test;
array p[3] (175 180 190);
array b[3] (  2   3   4);
array e[8] (. 1.1 0.8 0.9 1.2 1.0 0.7 0.6);
a=0.5772;
g=0.0123;
do t=1 to 3;
  dr=discrate(t,p,b,a,g,e);
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;EDIT:&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp; Took the second fraction out of the sum (&lt;FONT face="symbol"&gt;t&lt;/FONT&gt;=1, ..., 5), as this seems more plausible&amp;nbsp;mathematically (without knowing the background or source of the formula).&lt;/P&gt;</description>
    <pubDate>Sat, 04 Sep 2021 16:57:07 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-09-04T16:57:07Z</dc:date>
    <item>
      <title>Solve Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/765788#M242585</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;I need to calculate cost of capital based on the model&amp;nbsp;looks like below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cheema_3-1630632232865.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63261i2CCDD0C506002A85/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cheema_3-1630632232865.png" alt="cheema_3-1630632232865.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;All the variables in this model are known, except the discount rate&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cheema_4-1630632251555.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63262iEE9C4520A6CFC45D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cheema_4-1630632251555.png" alt="cheema_4-1630632251555.png" /&gt;&lt;/span&gt;.&lt;/P&gt;
&lt;P&gt;I’m entering a dead end to find useful code to solve the equation above, where only&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cheema_5-1630632251555.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63263i7EF344AFD1388312/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cheema_5-1630632251555.png" alt="cheema_5-1630632251555.png" /&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;is the unknown.&lt;/P&gt;
&lt;P&gt;If you know a solution to this problem, please comment, it is very much appreciated.&lt;/P&gt;
&lt;P&gt;Thank you very much.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Sep 2021 01:51:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/765788#M242585</guid>
      <dc:creator>MAC1430</dc:creator>
      <dc:date>2021-09-04T01:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: Solve Equation -Cost of capital</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/765820#M242607</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/39704"&gt;@MAC1430&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you can use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p1xoknqns865t7n1wehj6xarwhdb.htm" target="_blank" rel="noopener"&gt;SOLVE function&lt;/A&gt; in PROC FCMP:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Define function DISCRATE */

proc fcmp outlib=work.funcs.test;
function rhs(t, B[*], a, g, e[*], c);
  s=B[t];
  do tau=1 to 5;
    s = s + a*e[t+tau]/(1+g+c)**tau;
  end;
  s = s + a*e[t+5]*(1+g)/(c*(1+g+c)**5);
  return(s);
endfunc;
function discrate(t, P[*], B[*], a, g, e[*]);
  r=g+solve("RHS", {.}, P[t], t, B, a, g, e, .);
  return(r);
endfunc;
run;

/* Make function available */

options cmplib=work.funcs;

/* Apply function DISCRATE to arbitrary sample data */

data test;
array p[3] (175 180 190);
array b[3] (  2   3   4);
array e[8] (. 1.1 0.8 0.9 1.2 1.0 0.7 0.6);
a=0.5772;
g=0.0123;
do t=1 to 3;
  dr=discrate(t,p,b,a,g,e);
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;EDIT:&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp; Took the second fraction out of the sum (&lt;FONT face="symbol"&gt;t&lt;/FONT&gt;=1, ..., 5), as this seems more plausible&amp;nbsp;mathematically (without knowing the background or source of the formula).&lt;/P&gt;</description>
      <pubDate>Sat, 04 Sep 2021 16:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/765820#M242607</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-09-04T16:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Solve Equation -Cost of capital</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/765844#M242617</link>
      <description>&lt;P&gt;Do you have SAS/IML? Calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 12:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/765844#M242617</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-03T12:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Solve Equation -Cost of capital</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/765847#M242620</link>
      <description>&lt;P&gt;For more information about how to use the SOLVE function and PROC FCMP, see &lt;A href="https://blogs.sas.com/content/iml/2020/08/19/find-root-function-sas-data-step.html" target="_self"&gt;"Find the root of a function by using the SAS DATA step."&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The same article provides links to other root-finding methods in SAS. As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;points out, the easiest way to solve this equation is to &lt;A href="https://blogs.sas.com/content/iml/2014/02/05/find-the-root-of-a-function.html" target="_self"&gt;use the FROOT function in SAS/IML&lt;/A&gt;, if you have a license for SAS/IML.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 12:59:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/765847#M242620</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-09-03T12:59:02Z</dc:date>
    </item>
  </channel>
</rss>

