<?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: Solving Equation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766165#M242784</link>
    <description>&lt;P&gt;Thank you very much for the code and explanation around it.&lt;/P&gt;
&lt;P&gt;This is new knowledge and a learning process for me, if it's convenient, Could you kindly shed light on how the other solution&amp;nbsp;&lt;SPAN&gt;on each side of the pole at&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;r=−&lt;/EM&gt;&lt;SPAN&gt;1 looks like, using the SOLVE function?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Appreciate it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Mac&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Sep 2021 05:24:39 GMT</pubDate>
    <dc:creator>MAC1430</dc:creator>
    <dc:date>2021-09-06T05:24:39Z</dc:date>
    <item>
      <title>Solving Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/765994#M242687</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;I want to solve equation below to calculate r for each stock:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MAC1430_0-1630800270175.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63295i929296D55E466DAC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MAC1430_0-1630800270175.png" alt="MAC1430_0-1630800270175.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input stock$     y	B	P	F	g;
datalines;
A	1	12.1492	80.16	3.8886	0.3038
A	2	15.3785	63.54	4.8659	0.3769
A	3	11.5507	41.19	4.5454	0.205
A	4	15.1777	35.28	4.3858	0.1478
A	5	14.9545	52	5.7079	0.0644
A	6	15.8837	50.78	6.1861	-0.0636
A	7	19.3065	67.64	6.7226	-0.0915
A	8	21.6415	72.05	7.7686	-0.0553
A	9	23.6561	74.51	8.804	0.0005
A	10	27.2373	43.05	9.0739	0.123
B	1	6.3668	37.8	2.7893	0.3038
B	2	7.6967	35.4	3.238	0.3769
B	3	8.6812	29.3	3.2122	0.205
B	4	8.999	30.9	3.2352	0.1478
B	5	9.5064	29.75	3.5381	0.0644
B	6	10.1293	39.3	3.4308	-0.0636
B	7	12.2344	43.3	3.7561	-0.0915
B	8	13.2885	52	4.2523	-0.0553
B	9	13.9864	41.6	4.7464	0.0005
B	10	14.043	50.2	4.2598	0.123
C	1	1.4639	24.19	0.3939	0.3038
C	2	2.3384	19.52	1.3403	0.3769
C	3	2.626	7.96	-1.0251	0.205
C	4	2.7283	15.72	0.3156	0.1478
C	5	2.3651	11.81	0.049	0.0644
C	6	2.8771	16.9	0.964	-0.0636
C	7	3.532	18.84	1.1485	-0.0915
C	8	4.5199	21.66	2.0169	-0.0553
C	9	4.379	12.75	2.0582	0.0005
C	10	4.6028	24	0.9412	0.123
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you know a solution to this problem, please comment, it is very much appreciated.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Sep 2021 00:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/765994#M242687</guid>
      <dc:creator>MAC1430</dc:creator>
      <dc:date>2021-09-05T00:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: Solving Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766031#M242706</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's "just" algebra and that can de done with PROC IML.&lt;/P&gt;
&lt;P&gt;But for PROC IML, you need a license for SAS/IML (Interactive Matrix Language).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also do it with SAS/ETS (Econometrics and Time Series).&lt;/P&gt;
&lt;P&gt;PROC MODEL or PROC TMODEL (multithreaded version of PROC MODEL) can be used for solving equations.&lt;/P&gt;
&lt;P&gt;Maybe PROC SYSLIN is suited as well?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do not have SAS/IML nor SAS/ETS, it can probably be done with the data step as well (possibly in combination with PROC FCMP), but then you need to do some more preparation work to disentangle the formula.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sat, 04 Sep 2021 12:01:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766031#M242706</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-09-04T12:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: Solving Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766044#M242717</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;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/39704"&gt;@MAC1430&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to solve equation below to calculate r for each stock:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MAC1430_0-1630719926191.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63287i4909125045E976F3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MAC1430_0-1630719926191.png" alt="MAC1430_0-1630719926191.png" /&gt;&lt;/span&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;At first glance this formula looks similar to that in your &lt;A href="https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/765788/highlight/true#M242585" target="_blank" rel="noopener"&gt;previous post&lt;/A&gt;. However, the second of the two fractions now contains &lt;FONT face="symbol"&gt;t&lt;/FONT&gt;, which implies that it belongs under the sum (&lt;FONT face="symbol"&gt;t&lt;/FONT&gt;=1, ..., 5). But then the two fractions should be put into parentheses and also the first fraction could be factored out, which would simplify the formula. In your previous post the second fraction used the constant 5 instead of &lt;FONT face="symbol"&gt;t&lt;/FONT&gt;, suggesting that it does &lt;EM&gt;not&lt;/EM&gt; belong under the sum&amp;nbsp;(&lt;FONT face="symbol"&gt;t&lt;/FONT&gt;=1, ..., 5) -- which I've realized now. &lt;STRONG&gt;I have edited yesterday's solution accordingly.&lt;/STRONG&gt;&amp;nbsp;Sorry for the confusion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please double-check if your new formula is correct as posted or if the second fraction should contain something else in place of&amp;nbsp;&lt;FONT face="symbol"&gt;t&lt;/FONT&gt;&amp;nbsp;(similar to yesterday's formula).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either way the PROC FCMP code for the new formula will be analogous to yesterday's solution.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Sep 2021 17:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766044#M242717</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-09-04T17:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Solving Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766071#M242729</link>
      <description>&lt;P&gt;Hi Reinhard,&lt;/P&gt;
&lt;P&gt;Thank you very much for the comment.&lt;/P&gt;
&lt;P&gt;I updated the formula, you are right, the second fraction is not part of the sum function (I should have checked it more carefully, my bad).&lt;/P&gt;
&lt;P&gt;What I'm confused about the new equation is, the unknown r, is embeded in both numerator&amp;nbsp;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MAC1430_2-1630801193918.png" style="width: 210px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63302iBCC636AAD39A1CB9/image-dimensions/210x31?v=v2" width="210" height="31" role="button" title="MAC1430_2-1630801193918.png" alt="MAC1430_2-1630801193918.png" /&gt;&lt;/span&gt;&amp;nbsp;and denominator&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MAC1430_1-1630801159883.png" style="width: 79px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63301iA66240C24892B5C6/image-dimensions/79x29?v=v2" width="79" height="29" role="button" title="MAC1430_1-1630801159883.png" alt="MAC1430_1-1630801159883.png" /&gt;&lt;/span&gt;.&lt;/P&gt;
&lt;P&gt;In the first equation, the unknown is only in the denominator.&lt;/P&gt;
&lt;P&gt;Could you pls kindly show on how to solve the new equation using proc fcmp?&lt;/P&gt;
&lt;P&gt;Sorry, I'm not farmilar with this function, thus asking you again, your help is Veryyy much appreciated.&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Sep 2021 00:29:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766071#M242729</guid>
      <dc:creator>MAC1430</dc:creator>
      <dc:date>2021-09-05T00:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: Solving Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766136#M242764</link>
      <description>&lt;P&gt;Thanks for the updated formula and also for providing realistic sample data (in usable form).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The right-hand side of the equation -- a rational function in &lt;EM&gt;r&lt;/EM&gt; -- has singularities (poles) at &lt;EM&gt;r=−&lt;/EM&gt;1 and &lt;EM&gt;r=g&lt;/EM&gt;. I've examined a few particular cases and the common pattern was: one solution on each side of the pole at &lt;EM&gt;r=−&lt;/EM&gt;1 and one solution in a neighborhood of the pole at &lt;EM&gt;r=g&lt;/EM&gt;. So the first question is: Which of the three solutions do you want? For the time being I have focused on the solution near &lt;EM&gt;r=g&lt;/EM&gt; because it was always positive. But this is not guaranteed in general since &lt;EM&gt;g&lt;/EM&gt; can be negative, as we see in the sample data. It also depends on the data whether&lt;EM&gt; r&lt;SUB&gt;0&lt;/SUB&gt;&amp;lt;g&lt;/EM&gt; or &lt;EM&gt;r&lt;SUB&gt;0&lt;/SUB&gt;&amp;gt;g&lt;/EM&gt; for the solution &lt;EM&gt;r&lt;SUB&gt;0&lt;/SUB&gt;&lt;/EM&gt; near &lt;EM&gt;r=g&lt;/EM&gt;. This is a challenge for the SOLVE function because it requires an initial value as a starting point and it's likely a good idea to stay on &lt;EM&gt;one&lt;/EM&gt; side of the pole at &lt;EM&gt;r=g&lt;/EM&gt; while searching for the solution. The sign of the numerator of the last fraction seemed to be a useful criterion to distinguish between the two cases &lt;EM&gt; r&lt;SUB&gt;0&lt;/SUB&gt;&amp;lt;g&lt;/EM&gt;&amp;nbsp;and&amp;nbsp;&lt;EM&gt;r&lt;SUB&gt;0&lt;/SUB&gt;&amp;gt;g&lt;/EM&gt;. It worked for your sample data, but you may need to modify the criterion for (very) different data. To avoid difficulties with the pole, I've introduced a new (FCMP-internal) variable &lt;EM&gt;x&lt;/EM&gt; so that the solution can be written as &lt;EM&gt;r&lt;SUB&gt;0&lt;/SUB&gt; = g ±&lt;/EM&gt; exp(&lt;EM&gt;−x&lt;/EM&gt;*10000) with "+" or "-"&amp;nbsp;depending on the sign of the numerator of the last fraction. Thus the SOLVE function can solve for &lt;EM&gt;x&lt;/EM&gt; and the default initial value 0.001 is suitable (at least for your sample data).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know the technical term for the rate (?) &lt;EM&gt;r&lt;/EM&gt;&amp;nbsp;and therefore named the function &lt;EM&gt;X&lt;/EM&gt;RATE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code (allowing for &lt;FONT face="courier new,courier"&gt;y&lt;/FONT&gt; values up to 99 -- simply increase the array dimensions if you need more)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Define function XRATE */

proc fcmp outlib=work.funcs.test;
function rs(y, B[*], F[*], g, x);
  s=B[y];
  z=sign((F[y+5]-g*B[y+4])*(1+g))*exp(-x*1e4);
  do tau=1 to 5;
    s = s + (F[y+tau]-(g+z)*B[y+tau-1])/(1+g+z)**tau;
  end;
  s = s + (F[y+5]-(g+z)*B[y+4])*(1+g)/(z*(1+g+z)**5);
  return(s);
endfunc;
function xrate(y, p[*], B[*], F[*], g);
  r=g+sign((F[y+5]-g*B[y+4])*(1+g))*exp(-solve("RS", {.}, p[y], y, B, F, g, .)*1e4);
  return(r);
endfunc;
run;

/* Make function available */

options cmplib=work.funcs;

/* Apply function XRATE to dataset TEST */

data want;
array _B[99] _temporary_;
array _P[99] _temporary_;
array _F[99] _temporary_;
do until(last.stock);
  set test;
  by stock;
  _B[y]=B;
  _P[y]=P;
  _F[y]=F;
end;
do until(last.stock);
  set test;
  by stock;
  r=xrate(y,_P,_B,_F,g);
  output;
end;
call missing(of _B[*], of _P[*], of _F[*]);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Not surprisingly, the solutions for &lt;FONT face="courier new,courier"&gt;y&amp;gt;5&lt;/FONT&gt; are missing because the formula contains indices up to &lt;FONT face="courier new,courier"&gt;y+5&lt;/FONT&gt;, while &lt;FONT face="courier new,courier"&gt;10&lt;/FONT&gt; is the maximum of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;y&lt;/FONT&gt;&amp;nbsp;in the sample data. Note that all solutions are greater than the respective &lt;FONT face="courier new,courier"&gt;g&lt;/FONT&gt;, except for the case &lt;FONT face="courier new,courier"&gt;stock='B' &amp;amp; y=2&lt;/FONT&gt;, where the solution is found on the &lt;EM&gt;left&lt;/EM&gt; side of the pole at &lt;EM&gt;r=g&lt;/EM&gt;&amp;nbsp;because the &lt;FONT face="courier new,courier"&gt;sign(...)&lt;/FONT&gt; term is negative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As explained above, the SOLVE function (using the Gauss-Newton method) is maybe not ideal for a function with poles like this. So, if difficulties arise with your real data, you may want to explore other possibilities such as the FROOT function mentioned by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;in the &lt;A href="https://communities.sas.com/t5/SAS-Programming/Solve-Equation/m-p/765847/highlight/true#M242620" target="_blank" rel="noopener"&gt;previous thread&lt;/A&gt;. I couldn't test that because SAS/IML is not contained in my SAS license.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Sep 2021 18:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766136#M242764</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-09-05T18:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Solving Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766165#M242784</link>
      <description>&lt;P&gt;Thank you very much for the code and explanation around it.&lt;/P&gt;
&lt;P&gt;This is new knowledge and a learning process for me, if it's convenient, Could you kindly shed light on how the other solution&amp;nbsp;&lt;SPAN&gt;on each side of the pole at&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;r=−&lt;/EM&gt;&lt;SPAN&gt;1 looks like, using the SOLVE function?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Appreciate it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Mac&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 05:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766165#M242784</guid>
      <dc:creator>MAC1430</dc:creator>
      <dc:date>2021-09-06T05:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: Solving Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766245#M242829</link>
      <description>&lt;P&gt;I have extended the function definitions to include a new first argument &lt;EM&gt;w&lt;/EM&gt;, whose value 1, 2 or 3 determines whether a solution is searched &amp;lt; −1, &amp;gt; −1 or near &lt;EM&gt;g&lt;/EM&gt;. The corresponding solutions, if any, are stored in variables &lt;FONT face="courier new,courier"&gt;r1&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;r2&lt;/FONT&gt;&amp;nbsp;and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;r3&lt;/FONT&gt;, respectively.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Define function XRATE */

proc fcmp outlib=work.funcs.test;
function rs(w, y, B[*], F[*], g, x);
  select(w);
    when(1) z=-1-exp(-x*1e4); /* for a solution &amp;lt; -1 */
    when(2) z=-1+exp(-x*1e4); /* for a solution &amp;gt; -1 */
    when(3) z=g+sign((F[y+5]-g*B[y+4])*(1+g))*exp(-x*1e4); /* for a solution near g */
  end;
  s=B[y];
  do tau=1 to 5;
    s = s + (F[y+tau]-z*B[y+tau-1])/(1+z)**tau;
  end;
  s = s + (F[y+5]-z*B[y+4])*(1+g)/((z-g)*(1+z)**5);
  return(s);
endfunc;
function xrate(w, y, p[*], B[*], F[*], g);
  array solvopts[5] initial abconv relconv maxiter status (0.001 0.001 1.0e-6 100);
  t=exp(-solve("RS", solvopts, p[y], w, y, B, F, g, .)*1e4);
  select(w);
    when(1) r=-1-t; /* solution &amp;lt; -1 */
    when(2) r=-1+t; /* solution &amp;gt; -1 */
    when(3) r=g+sign((F[y+5]-g*B[y+4])*(1+g))*t; /* solution near g */
  end;
  return(r);
endfunc;
run;

/* Make function available */

options cmplib=work.funcs;

/* Apply function XRATE to dataset TEST */

data want;
array _B[99] _temporary_;
array _P[99] _temporary_;
array _F[99] _temporary_;
do until(last.stock);
  set test;
  by stock;
  _B[y]=B;
  _P[y]=P;
  _F[y]=F;
end;
do until(last.stock);
  set test;
  by stock;
  r1=xrate(1,y,_P,_B,_F,g);
  r2=xrate(2,y,_P,_B,_F,g);
  r3=xrate(3,y,_P,_B,_F,g);
  output;
end;
call missing(of _B[*], of _P[*], of _F[*]);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With your sample data, &lt;FONT face="courier new,courier"&gt;r3&lt;/FONT&gt; contains the solution near &lt;EM&gt;g&lt;/EM&gt; which we already found with the previous code version. In 12 of the 15 cases with potential solutions there are also (negative) solutions in &lt;FONT face="courier new,courier"&gt;r1&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;r2&lt;/FONT&gt;. Unfortunately, the remaining three cases cause error messages "&lt;FONT face="courier new,courier"&gt;ERROR: Exception occurred during subroutine call&lt;/FONT&gt;" in the log. As it turned out (I checked this only with simplified input data), it is possible that &lt;EM&gt;both&lt;/EM&gt; solutions near&amp;nbsp;−1 are &amp;lt;&amp;nbsp;−1, i.e., on the left side of the first pole. Hence, a missing value in &lt;FONT face="courier new,courier"&gt;r2&lt;/FONT&gt; would be the expected result, but a failed search for the non-existent solution in the interval (−1, &lt;EM&gt;g&lt;/EM&gt;] might run into the second pole, &lt;EM&gt;g&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Considering the graphs of some of the functions it seems possible theoretically that even more different cases exist -- depending on the data --, e.g., only one or no solution near&amp;nbsp;−1 or more than three solutions. After all, the polynomial in &lt;EM&gt;r&lt;/EM&gt; in the denominator has degree 5, so the graph is very "flexible" and thus challenging for a root-finding algorithm that uses derivatives. Maybe a different algorithm (than what is implemented in the SOLVE function) would be more suitable for your application, e.g., the bisection method. A sophisticated version of this is used by the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/imlug/imlug_langref_sect165.htm" target="_blank" rel="noopener"&gt;FROOT function&lt;/A&gt; in SAS/IML. In its basic form it is also implemented in the &lt;FONT face="courier new,courier"&gt;%Bisect&lt;/FONT&gt; macro found in the SESUG 2007 paper &lt;A href="https://analytics.ncsu.edu/sesug/2007/PO21.pdf" target="_blank" rel="noopener"&gt;Customized Base SAS implemented solvers&lt;/A&gt;. I used this macro occasionally in the past, but haven't applied it to your function yet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;%Bisect&lt;/FONT&gt; macro and the SOLVE function would need carefully selected initial values to find all solutions in some cases. I've introduced an "options array" (cf. &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p1xoknqns865t7n1wehj6xarwhdb.htm" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt;) into the code to facilitate testing different initial values (first element of the array &lt;FONT face="courier new,courier"&gt;solvopts&lt;/FONT&gt;). The question remains whether &lt;EM&gt;all&lt;/EM&gt; (positive and negative) solutions are really sensible to interpret in practice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 18:07:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766245#M242829</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-09-06T18:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: Solving Equation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766280#M242843</link>
      <description>&lt;P&gt;Thank you very much, it works fine &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 23:49:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766280#M242843</guid>
      <dc:creator>MAC1430</dc:creator>
      <dc:date>2021-09-06T23:49:52Z</dc:date>
    </item>
  </channel>
</rss>

