<?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: FCMP complex loop to write function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/FCMP-complex-loop-to-write-function/m-p/319307#M70090</link>
    <description>&lt;P&gt;Is this what you need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" face="SAS Monospace" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; i ne j and j ne k and k ne i then &lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;fx = fx + ((y[i,k]*y[k,j])-(x[i]/x[j]))**&lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;2&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Dec 2016 16:25:46 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-12-15T16:25:46Z</dc:date>
    <item>
      <title>FCMP complex loop to write function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-complex-loop-to-write-function/m-p/319300#M70085</link>
      <description>&lt;P&gt;I'm trying to write a following function that I would like to minimize using a sas optlso. But I'm having difficulty in figuring out the logic. Any help in creating the logic would be very helpful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is the function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/6391i016614C2FA93D013/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="equation.JPG" title="equation.JPG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The part that I cannot figure out is i ne j ne k ne i. If you can modify the below code to reflecy te a&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is a reproducible example. Any help would be greating appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;BR /&gt;proc fcmp outlib=sasuser.myfuncs.mypkg;
   function fdef1(x1, x2,x3,x4,x5,x6,x7);
   array x[7];
   array y[7,7] /nosym (	1.0000 4.0000 9.0000 6.0000 6.0000 5.0000 5.0000 
     						0.2500 1.0000 7.0000 5.0000 5.0000 3.0000 4.0000 
     						0.1111 0.1429 1.0000 0.2000 0.2000 0.1429 0.2000 
    						0.1667 0.2000 5.0000 1.0000 1.0000 0.3333 0.3333 
     						0.1667 0.2000 5.0000 1.0000 1.0000 0.3333 0.3333 
     						0.2000 0.3333 7.0000 3.0000 3.0000 1.0000 2.0000 
     						0.2000 0.2500 5.0000 3.0000 3.0000 0.5000 1.0000); 

	fx = 0;
 	do i= 1 to dim(y);
		do j = i+1 to dim(y);
			do k = 1 to dim(y);
				fx = fx + ((y[i,k]*y[k,j])-(x[i]/x[j]))**2;
			end;
		end;
	end;
	return(fx);
   endsub;
run;&lt;/PRE&gt;
&lt;P&gt;One additional question: &amp;nbsp;Is there a way to print out the indices i j and k in the loop to a SAS log/dataset to QC ?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 16:14:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-complex-loop-to-write-function/m-p/319300#M70085</guid>
      <dc:creator>Forecaster</dc:creator>
      <dc:date>2016-12-15T16:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: FCMP complex loop to write function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-complex-loop-to-write-function/m-p/319307#M70090</link>
      <description>&lt;P&gt;Is this what you need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" face="SAS Monospace" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; i ne j and j ne k and k ne i then &lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;fx = fx + ((y[i,k]*y[k,j])-(x[i]/x[j]))**&lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;2&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 16:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-complex-loop-to-write-function/m-p/319307#M70090</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-15T16:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: FCMP complex loop to write function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-complex-loop-to-write-function/m-p/319373#M70131</link>
      <description>&lt;P&gt;Thank you very much. Can you please also let me know if I can print i,j,k to the log or lst ?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 19:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-complex-loop-to-write-function/m-p/319373#M70131</guid>
      <dc:creator>Forecaster</dc:creator>
      <dc:date>2016-12-15T19:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: FCMP complex loop to write function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FCMP-complex-loop-to-write-function/m-p/319391#M70139</link>
      <description>&lt;P&gt;Likely not to LST,&amp;nbsp;&amp;nbsp;but did you try something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Put "In function&amp;nbsp;FDEF1 " i=;&lt;/P&gt;
&lt;P&gt;Completely untested though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can see a use for debugging with this but since functions can get many times in a procedure or datastep I would recommend not leaving them in the final version.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 21:09:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FCMP-complex-loop-to-write-function/m-p/319391#M70139</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-15T21:09:12Z</dc:date>
    </item>
  </channel>
</rss>

