<?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: Recursion in proc fcmp in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209924#M267340</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;as a workaround you can use a static array.&lt;/P&gt;&lt;P style="padding: 0 0 0 60px; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="text-decoration: line-through;"&gt;&amp;nbsp; D = dim(boxes);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding: 0 0 0 60px; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="text-decoration: line-through;"&gt;&amp;nbsp; array temp[1] / nosymbols;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding: 0 0 0 60px; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="text-decoration: line-through;"&gt;&amp;nbsp; call dynamic_array(temp,D);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding: 0 0 0 60px; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="padding: 0 0 0 60px; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; array temp[999];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found this sentence in the doc:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, 'Arial Unicode MS', geneva, 'Lucida Grande', sans-serif; font-size: 13.4399995803833px; background-color: #ffffff;"&gt;When an array is resized, the resized array is available only within the routine that resized it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#n0ht4c42g9m027n1fbd67lu2y8ws.htm" style="font-family: arial, 'Arial Unicode MS', geneva, 'Lucida Grande', sans-serif; font-size: 13.4399995803833px; line-height: 1.5em;" title="http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#n0ht4c42g9m027n1fbd67lu2y8ws.htm"&gt;Base SAS(R) 9.3 Procedures Guide, Second Edition&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Yes, you are calling the same routine, but still it is another "instance" of the MyFun function.&lt;/P&gt;&lt;P&gt;And because boxes is listed in the outargs statement, it is passed by reference, so the temp array basically becomes the boxes array (but not available, because it was resized). &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 06 May 2015 12:54:00 GMT</pubDate>
    <dc:creator>gergely_batho</dc:creator>
    <dc:date>2015-05-06T12:54:00Z</dc:date>
    <item>
      <title>Recursion in proc fcmp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209923#M267339</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Background: &lt;A href="http://programmers.stackexchange.com/questions/281820/algorithms-for-allocating-n-balls-into-m-boxes"&gt;http://programmers.stackexchange.com/questions/281820/algorithms-for-allocating-n-balls-into-m-boxes&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying a using recursion to update an array;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;data Test;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; N = 14;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; M = 3;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; array boxes[4] boxes1-boxes4 (4*.);&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; V = MyFun(N,M,boxes);&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;proc fcmp outlib=Work.Functions.Test;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; function MyFun(N,M,boxes&lt;LI&gt;) varargs;&lt;/LI&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; outargs boxes;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; if M = 1 then do;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; Total = 0;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; do i = 0 to N;&lt;/P&gt;&lt;P style="padding-left: 90px;"&gt;&amp;nbsp; if Func1(i) &amp;gt; Total then do;&lt;/P&gt;&lt;P style="padding-left: 120px;"&gt;&amp;nbsp; Total = Func1(i);&lt;/P&gt;&lt;P style="padding-left: 120px;"&gt;&amp;nbsp; boxes[1] = i;&lt;/P&gt;&lt;P style="padding-left: 90px;"&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; if M = 2 then do;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; Total = 0;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; do i = 0 to N;&lt;/P&gt;&lt;P style="padding-left: 90px;"&gt;&amp;nbsp; do j = 0 to N-i;&lt;/P&gt;&lt;P style="padding-left: 120px;"&gt;&amp;nbsp; if Func1(i) + Func2(j) &amp;gt; Total then do;&lt;/P&gt;&lt;P style="padding-left: 150px;"&gt;&amp;nbsp; Total = Func1(i) + Func2(j);&lt;/P&gt;&lt;P style="padding-left: 150px;"&gt;&amp;nbsp; boxes[1] = i;&lt;/P&gt;&lt;P style="padding-left: 150px;"&gt;&amp;nbsp; boxes[2] = j;&lt;/P&gt;&lt;P style="padding-left: 120px;"&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P style="padding-left: 90px;"&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; if M = 3 then do;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; Total = 0;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; D = dim(boxes);&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; array temp[1] / nosymbols;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; call dynamic_array(temp,D);&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; do i = 0 to N;&lt;/P&gt;&lt;P style="padding-left: 90px;"&gt;&amp;nbsp; do j = 0 to min(i,N-i);&lt;/P&gt;&lt;P style="padding-left: 120px;"&gt;&amp;nbsp; Total_New = MyFun(i-j,M-1,temp) + Func3(j);&lt;/P&gt;&lt;P style="padding-left: 120px;"&gt;&amp;nbsp; if Total_New &amp;gt; Total then do;&lt;/P&gt;&lt;P style="padding-left: 150px;"&gt;&amp;nbsp; Total = Total_New;&lt;/P&gt;&lt;P style="padding-left: 150px;"&gt;&amp;nbsp; boxes[1] = temp[1];&lt;/P&gt;&lt;P style="padding-left: 150px;"&gt;&amp;nbsp; boxes[2] = temp[2];&lt;/P&gt;&lt;P style="padding-left: 150px;"&gt;&amp;nbsp; boxes[3] = j;&lt;/P&gt;&lt;P style="padding-left: 120px;"&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P style="padding-left: 90px;"&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; return(Total);&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; endsub;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;run;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P&gt;For M &amp;lt; 3, this works. But When M = 3, Total_New = MyFun(i-j,M-1,temp) + Func3(j); doesn't update the array &lt;STRONG&gt;temp&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For M &amp;gt; 3, how can I automatically adjust &lt;STRONG&gt;Func3 to MyFun_for_that_M &lt;/STRONG&gt;? In fact, functions don't have the same prefix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any hint is greatly appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 May 2015 03:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209923#M267339</guid>
      <dc:creator>RandomBet</dc:creator>
      <dc:date>2015-05-06T03:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion in proc fcmp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209924#M267340</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;as a workaround you can use a static array.&lt;/P&gt;&lt;P style="padding: 0 0 0 60px; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="text-decoration: line-through;"&gt;&amp;nbsp; D = dim(boxes);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding: 0 0 0 60px; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="text-decoration: line-through;"&gt;&amp;nbsp; array temp[1] / nosymbols;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding: 0 0 0 60px; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="text-decoration: line-through;"&gt;&amp;nbsp; call dynamic_array(temp,D);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding: 0 0 0 60px; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="padding: 0 0 0 60px; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; array temp[999];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found this sentence in the doc:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, 'Arial Unicode MS', geneva, 'Lucida Grande', sans-serif; font-size: 13.4399995803833px; background-color: #ffffff;"&gt;When an array is resized, the resized array is available only within the routine that resized it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#n0ht4c42g9m027n1fbd67lu2y8ws.htm" style="font-family: arial, 'Arial Unicode MS', geneva, 'Lucida Grande', sans-serif; font-size: 13.4399995803833px; line-height: 1.5em;" title="http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#n0ht4c42g9m027n1fbd67lu2y8ws.htm"&gt;Base SAS(R) 9.3 Procedures Guide, Second Edition&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Yes, you are calling the same routine, but still it is another "instance" of the MyFun function.&lt;/P&gt;&lt;P&gt;And because boxes is listed in the outargs statement, it is passed by reference, so the temp array basically becomes the boxes array (but not available, because it was resized). &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 May 2015 12:54:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209924#M267340</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2015-05-06T12:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion in proc fcmp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209925#M267341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, not entirely seeing the reason for creating a compiled function for this.&amp;nbsp; Surely a simple set of loops in a datastep would be more efficient, as currently you hard code a loop value into the three blocks.&amp;nbsp; I would consider looking at what you want to achieve, and simplifying, maybe create a small macro if really needed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 May 2015 13:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209925#M267341</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-05-06T13:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion in proc fcmp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209926#M267342</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Question edited. Please see the problem background.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically it's about the complexity. When N,M are large, brute force using loops will be very very slow. And it's not convenient to apply the function on different M's. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 May 2015 15:39:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209926#M267342</guid>
      <dc:creator>RandomBet</dc:creator>
      <dc:date>2015-05-06T15:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion in proc fcmp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209927#M267343</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes. It's passed by ref instead of by value. But the question is I do need &lt;STRONG&gt;outargs &lt;/STRONG&gt;statements to update the boxes array. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 May 2015 15:42:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209927#M267343</guid>
      <dc:creator>RandomBet</dc:creator>
      <dc:date>2015-05-06T15:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion in proc fcmp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209928#M267344</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, you may want to add this to the Statistical procedures section, they may be able to give an actual procedure or simplified formula.&amp;nbsp; From my side, I still can't see how the compiled function is going to be any quicker than standard code.&amp;nbsp; In you example you have code blocks for if M=1, 2 or 3.&amp;nbsp; But if M=100, you going to end up with (100 * 9) + 100 lines of code, so from a maintenance point of view that is a lot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps some test data and required output would help, so I can fiddle around with it, example can the data be normalised, processed then transposed up again, does it need array processing.&amp;nbsp; Maybe have conditional sub loops etc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 May 2015 17:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209928#M267344</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-05-06T17:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion in proc fcmp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209929#M267345</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, you need the outargs statement if you want to update the array and want to be the result "permanent" (accessible from the calling code).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 May 2015 06:56:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recursion-in-proc-fcmp/m-p/209929#M267345</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2015-05-07T06:56:31Z</dc:date>
    </item>
  </channel>
</rss>

