<?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 exponential equation in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/440895#M69232</link>
    <description>&lt;P&gt;Thank you very much. I managed to solve my problem using your article&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2014/02/05/find-the-root-of-a-function.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2014/02/05/find-the-root-of-a-function.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here there is my code. Also I have a problem with adding z to a dataset.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro lambda;

%do i = 1 %to &amp;amp;n_obs.; 

  data _null_;
    set have (where = (a = &amp;amp;i.));
    call symput("d_0",d0);
    call symput("d_1",db);
    call symput("d_2",dt);
  run;

  proc iml;
    start Func(x);
      return( &amp;amp;d_0.**x - &amp;amp;d_1.**x - &amp;amp;d_2.**x );
    finish;

    intervals = {-10   10};  
    z = froot("Func", intervals);
  print z;
  quit;

%end;
%mend lambda;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2018 14:24:49 GMT</pubDate>
    <dc:creator>AlexSas</dc:creator>
    <dc:date>2018-02-28T14:24:49Z</dc:date>
    <item>
      <title>Solve exponential equation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/439666#M69146</link>
      <description>&lt;P&gt;Hi everyone. I need to solve this type of exponential equation:&amp;nbsp; &lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="scr1.png" style="width: 116px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18780iA1E89F0AA754FCDF/image-size/large?v=v2&amp;amp;px=999" role="button" title="scr1.png" alt="scr1.png" /&gt;&lt;/span&gt;where D1,D2 and D0 are existing numeric variables. How it is possible to solve this equation via SAS? So, how can I find x using SAS? Thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 12:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/439666#M69146</guid>
      <dc:creator>AlexSas</dc:creator>
      <dc:date>2018-02-23T12:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: Solve exponential equation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/439915#M69171</link>
      <description>&lt;P&gt;Check PROC NLIN to fit an non-linear model.&lt;/P&gt;
&lt;P&gt;Or Check FROOT() function in IML documentation.&lt;/P&gt;
&lt;P&gt;Or post it at OR forum, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt; might use OR code to solve it .&lt;/P&gt;
&lt;P&gt;And &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt; has wrote many blog to solve such kind of question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2015/06/08/fit-circle.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2015/06/08/fit-circle.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Feb 2018 05:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/439915#M69171</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-02-24T05:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: Solve exponential equation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/439965#M69173</link>
      <description>&lt;P&gt;This looks like a job for PROC NLIN.&amp;nbsp; You need a variable for the response, which is constantly zero. The following statements assume that the data for D0, D1, and D2 are in the data set MyData. I create a new data set called Have that appends a columns of zeros to use as the response. I also assume that you are interested in x &amp;gt; 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
set MyData;
ZERO = 0;
run;

proc nlin data=Have;
   parms x 1;
   bounds 0 &amp;lt; x;
   model ZERO = D0**x - D1**x + D2**x;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Feb 2018 19:40:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/439965#M69173</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-02-24T19:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: Solve exponential equation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/440823#M69227</link>
      <description>&lt;P&gt;I need to count x for each set of D0, D1 and D2. But I don't actually understand what does the code that you provided. I attach screenshots of my dataset and result.&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;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="My dataset." style="width: 376px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18869iC469C4554927281C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Scrn_1.png" alt="My dataset." /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;My dataset.&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Result" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18871iB753318BD92EA5D0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Scrn_2.jpg" alt="Result" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Result&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Log" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18870i1C939381EA58748A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Scrn_3.jpg" alt="Log" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Log&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 09:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/440823#M69227</guid>
      <dc:creator>AlexSas</dc:creator>
      <dc:date>2018-02-28T09:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: Solve exponential equation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/440833#M69228</link>
      <description>&lt;P&gt;I don't know what "&lt;SPAN&gt;count x for each set of D0, D1 and D2" means. The procedure fits a nonlinear regression model that finds the value of x that best fits the model to the entire set of observations. &lt;A href="http://go.documentation.sas.com/?docsetId=statug&amp;amp;docsetVersion=14.3&amp;amp;docsetTarget=statug_nlin_overview.htm&amp;amp;locale=en" target="_self"&gt;The SAS documentation gives an overview of PROC NLIN.&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't want to see the iteration history, you can use the&amp;nbsp;NOITPRINT option on the PROC NLIN statement. The important line in the output&amp;nbsp;is observation 26 (WHERE=(_TYPE_="FINAL")), which says that the best fit of the model&amp;nbsp;to your data is to make x a very small positive number&amp;nbsp;(essentially 0). When x=0, the equation reduces to 1-1+1=0 + eps, where eps is normal random error. This result seems to indicate that this model is not a good fit to the data.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 11:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/440833#M69228</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-02-28T11:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Solve exponential equation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/440843#M69229</link>
      <description>&lt;P&gt;"Count x for each set of D0,D1 and D2" means, for instance: if D0 = 25, D1=24 and D2 = 7 (obs N 17 in my dataset) then I have 25^x - 24^x - 7^x = 0. For this example x = 2, because 25^2 - 24^2 - 7^2 = 625 - 576 - 49 = 0.&lt;/P&gt;&lt;P&gt;Exapmple №2: if D0 = 4.5, D1 = 4 and D2 = 3 then x =3, because 4.5^3 - 4^3 - 3^3 = 91 - 64 - 27 = 0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I understand that I should look on observation&amp;nbsp;&lt;SPAN&gt;WHERE=&lt;/SPAN&gt;&lt;SPAN&gt;(_TYPE_="FINAL").&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 11:27:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/440843#M69229</guid>
      <dc:creator>AlexSas</dc:creator>
      <dc:date>2018-02-28T11:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: Solve exponential equation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/440892#M69231</link>
      <description>&lt;P&gt;Ah, I see.&amp;nbsp;You want to each observation to represent a DIFFERENT equation and you want a DIFFERENT value of x for each observation. I had assumed you wanted a single value of x that would fit all the data in a least squares sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your situation, each row represents an equation to be solved. Unfortunately, there is no reason to think that this equation has a solution for arbitrary values of D0, D1, and D2. For example, observations 9 and 28 in your data have&lt;/P&gt;
&lt;P&gt;D0&amp;gt;0&amp;nbsp;and D1=D2. The equation becomes D2^x = 0 which has no solution.&amp;nbsp;You might want to rethink (or explain) what you are trying to accomplish and describe where these numbers come. Clearly, some do not&amp;nbsp;satisfy the equation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the ones that do, you can&amp;nbsp;define&lt;/P&gt;
&lt;P&gt;f(x) = D0^x - D1^x + D2^x&lt;/P&gt;
&lt;P&gt;and solve for the root of f. Obviously f(0) &amp;gt; 0, so x=0 is never a root of f.&amp;nbsp;A root is found in (-infinity, 0) or (0,infinity), depending on the values of the parameters. For the first few observation in your data set, the roots occur for x&amp;lt;0, as shown by the following graph. (If you know that x&amp;lt;0 always, that will simplify matters.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input D0 D1 D2;
ZERO = 0;
ID = _N_;
datalines;
22    7.07  22
22.02 7.28  19.03
21    10.05 19
19.03 8.06  19.03
17.03 8.94  15
;

data GraphIt;
set Have;
do x = -2 to 0 by 0.1;
   y = D0**x - D1**x + D2**x;
   output;
end;
run;

proc sgplot data=GraphIt;
   series x=x y=y / group=ID;
   refline 0 / axis=y;
   yaxis min=-0.2 max=0.2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGPlot73.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18877i5335767CC59A2EBB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SGPlot73.png" alt="SGPlot73.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you don't seem familiar with PROC NLIN,&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2011/08/03/finding-the-root-of-a-univariate-function.html" target="_self"&gt;the simplest way to&amp;nbsp;find the root of a univariate function&lt;/A&gt;&amp;nbsp;in SAS is to use the&amp;nbsp;FROOT function in SAS/IML&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
start Func(x) global (D0, D1, D2);
   return( D0**x - D1**x + D2**x );
finish;

use Have;
read all var {D0 D1 D2} into D;
close;

x = j(nrow(D),1);
do i = 1 to nrow(D);
   D0 = D[i,1]; D1 = D[i,2]; D2 = D[i,3];  
   x[i] = froot("Func", {-2 0});
end;
print x;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't have access to&amp;nbsp;SAS/IML software, you'll have to learn how to use PROC NLIN:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options nonotes;
proc nlin data=Have noprint noitprint
          outest=PE(where=(_TYPE_="FINAL"));
   by ID;
   parms x -1;
   bounds x &amp;lt; 0;
   model ZERO = D0**x - D1**x + D2**x;
run;
options notes;

proc print data=PE noobs;
   var ID x;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Feb 2018 14:11:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/440892#M69231</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-02-28T14:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: Solve exponential equation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/440895#M69232</link>
      <description>&lt;P&gt;Thank you very much. I managed to solve my problem using your article&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2014/02/05/find-the-root-of-a-function.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2014/02/05/find-the-root-of-a-function.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here there is my code. Also I have a problem with adding z to a dataset.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro lambda;

%do i = 1 %to &amp;amp;n_obs.; 

  data _null_;
    set have (where = (a = &amp;amp;i.));
    call symput("d_0",d0);
    call symput("d_1",db);
    call symput("d_2",dt);
  run;

  proc iml;
    start Func(x);
      return( &amp;amp;d_0.**x - &amp;amp;d_1.**x - &amp;amp;d_2.**x );
    finish;

    intervals = {-10   10};  
    z = froot("Func", intervals);
  print z;
  quit;

%end;
%mend lambda;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 14:24:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Solve-exponential-equation/m-p/440895#M69232</guid>
      <dc:creator>AlexSas</dc:creator>
      <dc:date>2018-02-28T14:24:49Z</dc:date>
    </item>
  </channel>
</rss>

