<?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: IRR function from IML in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IRR-function-from-IML/m-p/19602#M50</link>
    <description>I have it working now after a small fix in the code.

Message was edited by: model_coder</description>
    <pubDate>Fri, 20 Nov 2009 21:12:01 GMT</pubDate>
    <dc:creator>model_coder</dc:creator>
    <dc:date>2009-11-20T21:12:01Z</dc:date>
    <item>
      <title>IRR function from IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IRR-function-from-IML/m-p/19599#M47</link>
      <description>Is it possible to call IRR function from IML?</description>
      <pubDate>Thu, 19 Nov 2009 17:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IRR-function-from-IML/m-p/19599#M47</guid>
      <dc:creator>model_coder</dc:creator>
      <dc:date>2009-11-19T17:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: IRR function from IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IRR-function-from-IML/m-p/19600#M48</link>
      <description>Yes, you can. &lt;BR /&gt;
&lt;BR /&gt;
I'll present a general technique for writing a module that "wraps" a Base SAS function so that it becomes "vectorized."  (This technique is adapted from code that will appear in my forthcoming book &lt;I&gt;Statistical Programming with SAS/IML Software: An Introduction&lt;/I&gt;, SAS Press, 2010.)&lt;BR /&gt;
&lt;BR /&gt;
The issue, for those not familiar with calling Base SAS functions, is that some Base SAS functions string out their arguments in a list, whereas in SAS/IML it is convenient to be able to pass a vector of values.  For the case of the IRR function, you can call IRR from IML explicitly by forming a list:&lt;BR /&gt;
&lt;BR /&gt;
proc iml;&lt;BR /&gt;
/* call Base SAS function directly to find the answer */&lt;BR /&gt;
rate1 = IRR(1,-400,100,200,300); &lt;BR /&gt;
print rate1;&lt;BR /&gt;
&lt;BR /&gt;
However, in SAS/IML the  parameters are typically in a vector such as &lt;BR /&gt;
c = {-400,100,200,300};&lt;BR /&gt;
and you cannot call IRR as&lt;BR /&gt;
rate2 = IRR(1,c); /* WRONG! Can't send vector to function expecting a list */&lt;BR /&gt;
&lt;BR /&gt;
How can we call the Base SAS function? The key is to define a module that uses the PUTN function to convert the numeric parameters to a long, comma, separated list, then call the EXECUTE subroutine.&lt;BR /&gt;
&lt;BR /&gt;
/* Call the IRR function in Base SAS. &lt;BR /&gt;
   This technique works for any Base SAS function that &lt;BR /&gt;
   is expecting a list of arguments instead of a vector.&lt;BR /&gt;
   Rick Wicklin */&lt;BR /&gt;
start myIRR(freq, c);&lt;BR /&gt;
   /* convert numeric matrices a single string */&lt;BR /&gt;
   args = strip(putn(freq,"BEST12.")); /* string of the freq value */&lt;BR /&gt;
   cc = strip(putn(c, "BEST12."));     /* character vector of c */&lt;BR /&gt;
   do i = 1 to nrow(cc)*ncol(cc);      /* concatenate all values */&lt;BR /&gt;
      args = concat(args, ",", strip(cc&lt;I&gt;)); &lt;BR /&gt;
   end;&lt;BR /&gt;
   cmd = "rate = IRR(" + args + ");" ;  /* Base function call, as a string */&lt;BR /&gt;
   call execute(cmd); /* execute the string  */&lt;BR /&gt;
   return (rate); /* return result from Base SAS function */&lt;BR /&gt;
finish;&lt;BR /&gt;
&lt;BR /&gt;
freq = 1;&lt;BR /&gt;
c = {-400,100,200,300};&lt;BR /&gt;
rate = myIRR(freq,c);   /* call Base SAS function with vector */&lt;BR /&gt;
print rate;&lt;/I&gt;</description>
      <pubDate>Thu, 19 Nov 2009 21:33:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IRR-function-from-IML/m-p/19600#M48</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2009-11-19T21:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: IRR function from IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IRR-function-from-IML/m-p/19601#M49</link>
      <description>Thanks Rick. This was very helpful.</description>
      <pubDate>Fri, 20 Nov 2009 18:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IRR-function-from-IML/m-p/19601#M49</guid>
      <dc:creator>model_coder</dc:creator>
      <dc:date>2009-11-20T18:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: IRR function from IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IRR-function-from-IML/m-p/19602#M50</link>
      <description>I have it working now after a small fix in the code.

Message was edited by: model_coder</description>
      <pubDate>Fri, 20 Nov 2009 21:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IRR-function-from-IML/m-p/19602#M50</guid>
      <dc:creator>model_coder</dc:creator>
      <dc:date>2009-11-20T21:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: IRR function from IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IRR-function-from-IML/m-p/19603#M51</link>
      <description>As model_coder mentions, there is a typo in the program. &lt;BR /&gt;
The statement inside the DO loop should say:&lt;BR /&gt;
args = concat(args, ",", strip(cc&lt;I&gt;));&lt;/I&gt;</description>
      <pubDate>Fri, 05 Mar 2010 13:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IRR-function-from-IML/m-p/19603#M51</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2010-03-05T13:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: IRR function from IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IRR-function-from-IML/m-p/19604#M52</link>
      <description>Rats: The blog software seems to "eat" certain character sequences. Very annoying.&lt;BR /&gt;
The statement inside the DO loop should say:&lt;BR /&gt;
args = concat(args, ",", strip(cc [ i ])); /* LEFT_BRACKET i RIGHT_BRACKET */</description>
      <pubDate>Fri, 05 Mar 2010 13:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IRR-function-from-IML/m-p/19604#M52</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2010-03-05T13:26:21Z</dc:date>
    </item>
  </channel>
</rss>

