<?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: PROC iml froot to solve univariate equation in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-iml-froot-to-solve-univariate-equation/m-p/574724#M4749</link>
    <description>&lt;P&gt;Thanks Imvash for your hint. I corrected the place. But still, it does not function.&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jul 2019 19:04:01 GMT</pubDate>
    <dc:creator>Dingdang</dc:creator>
    <dc:date>2019-07-18T19:04:01Z</dc:date>
    <item>
      <title>PROC iml froot to solve univariate equation</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-iml-froot-to-solve-univariate-equation/m-p/574663#M4747</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am new to proc iml. I read that froot function could replicate excel sovler. I try to solve&amp;nbsp;an equation towards the variable x, which is supposed to&amp;nbsp;a number between&amp;nbsp;-1 and 1, &amp;nbsp;but I got the error: invalid Operation. I am guessing I put in the wrong bound. Could someone please help me with this Problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; D0 D1 D2 D3;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt; ZERO = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID = _N_;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;0.1 0.45 100 80&lt;/P&gt;
&lt;P&gt;0.05 0.5 200 150&lt;/P&gt;
&lt;P&gt;0.3 0.45 300 180&lt;/P&gt;
&lt;P&gt;0.5 0.6 400 200&lt;/P&gt;
&lt;P&gt;0.15 0.6 500 200&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;iml&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;start&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Func (x) global (D0, D1, D2, D3);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;return&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ((CDF(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'NORMAL'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,(Quantile(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'NORMAL'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,D1) + sqrt(x)*Quantile(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'NORMAL'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;.999&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;))/sqrt(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-x), &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;)-D0)*D1*D2 - D3);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;finish&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;use&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;read&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; all &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;var&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; {D0 D1 D2 D3} &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;into&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; D;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;close&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;x=j(nrow(D),&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;to&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; nrow(D);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt; D0= D[i,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;]; D1= D[i, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;]; D2 = D[i, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;]; D4 =D[i,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;]; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt; x[i]=froot(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;"Func"&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;, {-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;});&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;print&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; x;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 19:02:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-iml-froot-to-solve-univariate-equation/m-p/574663#M4747</guid>
      <dc:creator>Dingdang</dc:creator>
      <dc:date>2019-07-18T19:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: PROC iml froot to solve univariate equation</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-iml-froot-to-solve-univariate-equation/m-p/574674#M4748</link>
      <description>&lt;P&gt;you clearly have an unbalanced parentheses in your return statement in Func(x). Try fixing it first.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 16:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-iml-froot-to-solve-univariate-equation/m-p/574674#M4748</guid>
      <dc:creator>imvash</dc:creator>
      <dc:date>2019-07-18T16:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: PROC iml froot to solve univariate equation</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-iml-froot-to-solve-univariate-equation/m-p/574724#M4749</link>
      <description>&lt;P&gt;Thanks Imvash for your hint. I corrected the place. But still, it does not function.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 19:04:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-iml-froot-to-solve-univariate-equation/m-p/574724#M4749</guid>
      <dc:creator>Dingdang</dc:creator>
      <dc:date>2019-07-18T19:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: PROC iml froot to solve univariate equation</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-iml-froot-to-solve-univariate-equation/m-p/574754#M4751</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input D0 D1 D2 D3;
	datalines;
0.1 0.45 100 80
0.05 0.5 200 150
0.3 0.45 300 180
0.5 0.6 400 200
0.15 0.6 500 200
;;
run;

proc iml;
	start Func (x) global (D0, D1, D2, D3);
		return ((CDF('NORMAL',(Quantile('NORMAL',D1) + sqrt(x)*Quantile('NORMAL', .999))/sqrt(1-x), 0, 1)-D0)*D1*D2 - D3);
	finish;

	use have;
		read all var {D0 D1 D2 D3} 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];
		D3 = D[i, 4];
		x[i] = froot("Func", {0 0.999});
	end;
	print x;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This script does not return any error messages. You had introduced D4 in your loop; I changed it to D3. Your input x boundaries should be well-defined (greater than zero and less than 1, as you had sqrt(x) in your function and division by sqrt(1-x)). Apparently, you do not have any feasible solution in the first 4 iterations.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 19:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/PROC-iml-froot-to-solve-univariate-equation/m-p/574754#M4751</guid>
      <dc:creator>imvash</dc:creator>
      <dc:date>2019-07-18T19:45:35Z</dc:date>
    </item>
  </channel>
</rss>

