<?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: Using REPEAT function to calculate IRR in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985411#M379847</link>
    <description>&lt;P&gt;Hi Quickbluefish,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually this code will work as well. Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jit&lt;/P&gt;</description>
    <pubDate>Thu, 26 Mar 2026 13:19:47 GMT</pubDate>
    <dc:creator>jitb</dc:creator>
    <dc:date>2026-03-26T13:19:47Z</dc:date>
    <item>
      <title>Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985377#M379830</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a dataset of loans with variables loan or financed_amount, payment_amount (per month), and term of the loan in months. I would like to calculate the internal rate of return (IRR) as:&lt;/P&gt;
&lt;P&gt;IRR =&amp;nbsp;irr(1,-financed_amount, of %sysfunc(repeat(%str(payment_amount ),term-1))).&lt;/P&gt;
&lt;P&gt;However, this is giving me an error&amp;nbsp;&lt;/P&gt;
&lt;DIV id="sasLogError1_1774470209880" class="sasError"&gt;ERROR: Argument 2 to function REPEAT referenced by the %SYSFUNC or %QSYSFUNC macro function is&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;not a number.&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;If I substitute 60 for (term-1) in the equation, it works.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;Any help would be much appreciated. Thanks.&lt;/DIV&gt;</description>
      <pubDate>Wed, 25 Mar 2026 20:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985377#M379830</guid>
      <dc:creator>jitb</dc:creator>
      <dc:date>2026-03-25T20:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985378#M379831</link>
      <description>&lt;P&gt;It would be extremely helpful if you showed us the ENTIRE log for this data step (not a small portion of the log).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, as far as I can tell, there is no need for %sysfunc here, yet you chose to use it even though no macro variables are present.&amp;nbsp;As far as I can tell, there is no need for %str here, yet you chose to use it even though no macro variables are present. If payment_amount and term are data set variables, %sysfunc and %str cannot access the values of a data set variable. Therefore, %sysfunc sees text as the second argument of the REPEAT function. The text is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;term-1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which is not a number, and not a reference to a data step variable, hence the error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you remove %sysfunc and %str and their associated parentheses, this might work.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2026 21:20:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985378#M379831</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2026-03-25T21:20:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985380#M379832</link>
      <description>&lt;P&gt;You can do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let trm=60;
%let pmt=4000;
%let fin=18000;

%let IRR = %sysfunc(irr(1,-&amp;amp;fin, %sysfunc(repeat(&amp;amp;pmt, %eval(&amp;amp;trm-1)))));
%put &amp;amp;=IRR;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Mar 2026 22:43:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985380#M379832</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2026-03-25T22:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985381#M379833</link>
      <description>&lt;P&gt;The macro code (%SYSFUNC) is resolved&amp;nbsp;&lt;U&gt;before&lt;/U&gt; the DATA step is even compiled, much less executed. Therefore you cannot use DATA step variable values there.&lt;/P&gt;
&lt;P&gt;Please describe in detail what you want to achieve, including the data that shall drive the code.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2026 22:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985381#M379833</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2026-03-25T22:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985382#M379834</link>
      <description>&lt;P&gt;Thank you, Paige. I will try without the %sysfunc and %str.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2026 23:47:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985382#M379834</guid>
      <dc:creator>jitb</dc:creator>
      <dc:date>2026-03-25T23:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985383#M379835</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dataset has a row for each loan given to a customer. Each row has the monthly payment to be made by the customer and is in the variable Payment_Amount. All Payment_Amount values are identical. The loan amount given to the customer is in Financed_Amount. The number of payments to be made (monthly) is in the variable term. I would like to calculate the IRR based on these variables in a data step for each row.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2026 23:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985383#M379835</guid>
      <dc:creator>jitb</dc:creator>
      <dc:date>2026-03-25T23:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985384#M379836</link>
      <description>&lt;P&gt;Thank you for this code. However, I need to calculate in a data step as variable values are different for each row.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2026 23:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985384#M379836</guid>
      <dc:creator>jitb</dc:creator>
      <dc:date>2026-03-25T23:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985385#M379837</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* create some test data ;
data test;
infile cards dsd truncover firstobs=1 dlm=',';
length finamt pmtamt term 8;
input finamt pmtamt term;
cards;
18000,4000,60
12000,7500,60
32000,11000,72
;
run;

proc sql noprint; 
select max(term) into :maxterm trimmed from test; 
quit;

data irr;
set test;
array T {&amp;amp;maxterm} _temporary_;
call missing(of T[*]);
do i=1 to (term-1);
	T[i]=pmtamt;
end;
irr=irr(1, -finamt, of T[*]);
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Mar 2026 01:57:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985385#M379837</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2026-03-26T01:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985386#M379838</link>
      <description>&lt;P&gt;The REPEAT() function is for making a long string by repeating shorter strings N+1 times.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt; 87         data test;
 88           s='AB ';
 89           l=repeat(s,2);
 90           put (s l) (=:$quote./);
 91         run;
 
 s="AB"
 l="AB AB AB"&lt;/PRE&gt;
&lt;P&gt;That is not going to be very useful for working with NUMBERS.&lt;/P&gt;
&lt;P&gt;Now it might be useful when used in macro code to generate CODE.&amp;nbsp; But then it needs to generate the COMMAs also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With actual data it would probably be better to put the values into an ARRAY and then pass the ARRAY of values to the IRR() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is not clear what data you have from the description.&amp;nbsp; Do you have one observation per payment per load ID?&amp;nbsp; If so then perhaps something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do i=1 by 1 until(last.id);
    set have end=eof;
    by id;
    pmts[i] = payment_amount ;
  end;
  irr = irr(12,-financed_amount,of pmts[*]);
  drop payment_amount i pmts: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So for each ID you read in ALL of the PAYMENT_AMOUNT values and put them into the ARRAY.&amp;nbsp; (Just make the size of the array larger than the maximum number of payments per loan.)&amp;nbsp; &amp;nbsp;The DO loop will collapse all of the observations per loan into one observation so that when it ends you have all of the payment amounts in the array.&amp;nbsp; Then just pass the whole array to IRR() and it will ignore the missing values are the end of the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you said they are monthly payments use 12 as the frequency value to pass to IRR().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now if instead you just have one observation per loan ID then instead use a different DO loop.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have end=eof;
  by id;
  array pmts[360] ;
  do i=1 to TERM ;
    pmts[i] = payment_amount ;
  end;
  irr = irr(12,-financed_amount,of pmts[*]);
  drop i pmts: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Again just make the array size larger than the maximum value or the TERM variable across all of the loans in the dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2026 02:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985386#M379838</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-03-26T02:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985389#M379841</link>
      <description>&lt;P&gt;That would be very helpful if you could post some real/dummy data to explain your issue.&lt;/P&gt;
&lt;P&gt;Here is an example for solving your issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input financed_amount payment_amount term;
cards;
400 100 5
400 200 3
400 300 2
;

filename x temp;
data _null_;
 set have end=last;
 file x;
 length repeat $ 2000;
 do i=1 to term;
  repeat=catx(',',repeat,payment_amount);
 end;
 if _n_=1 then put 'data want;';
 put 'financed_amount=' financed_amount ';payment_amount=' payment_amount ';term=' term ';irr=irr(1,-' financed_amount ',' repeat ');output;';
 if last then put 'run;';
run;

&lt;STRONG&gt;%include x/source;&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2026 07:28:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985389#M379841</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-03-26T07:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985394#M379842</link>
      <description>&lt;P&gt;So,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236136"&gt;@jitb&lt;/a&gt;&amp;nbsp;, I would like to briefly summarize the responses so far. In order for you to have the best chance of getting good replies in the future, please keep these things in mind:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;When you are having problems, we need a clear explanation of what you are trying to do. &lt;STRONG&gt;Do not assume that because you posted code that doesn't work, we know what you want.&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;We also need to know you think the correct answer is, or at least the correct thing for the code to be doing.&lt;/LI&gt;
&lt;LI&gt;We need a portion of your SAS data set, or we need made up data as long as it illustrates the problem. Please follow these &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions and examples&lt;/A&gt; to provide the data.&lt;/LI&gt;
&lt;LI&gt;If there are errors in the log, please show us the LOG (start to finish) for the DATA step or PROC that you are having errors in. Do not show us tiny portions of the log.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2026 08:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985394#M379842</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2026-03-26T08:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985407#M379844</link>
      <description>&lt;P&gt;Thank you, Tom for your solution. The second code is the appropriate one for my data as there is just one observation per loan ID. Since you used 12 as the frequency, I am assuming the IRR is an annual rate? Am I misunderstanding this? Thanks again!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jit&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2026 13:06:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985407#M379844</guid>
      <dc:creator>jitb</dc:creator>
      <dc:date>2026-03-26T13:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985408#M379845</link>
      <description>&lt;P&gt;This did not work as the REPEAT function seems to be basically for characters and not numbers. I appreciate your notes on describing the problem more thoroughly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jit&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2026 13:08:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985408#M379845</guid>
      <dc:creator>jitb</dc:creator>
      <dc:date>2026-03-26T13:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985409#M379846</link>
      <description>&lt;P&gt;Thank you for the code. This would have worked if I had multiple observations per loan ID. However, I just have one obs per ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jit&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2026 13:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985409#M379846</guid>
      <dc:creator>jitb</dc:creator>
      <dc:date>2026-03-26T13:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985411#M379847</link>
      <description>&lt;P&gt;Hi Quickbluefish,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually this code will work as well. Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jit&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2026 13:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985411#M379847</guid>
      <dc:creator>jitb</dc:creator>
      <dc:date>2026-03-26T13:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985413#M379848</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236136"&gt;@jitb&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, Tom for your solution. The second code is the appropriate one for my data as there is just one observation per loan ID. Since you used 12 as the frequency, I am assuming the IRR is an annual rate? Am I misunderstanding this? Thanks again!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jit&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes.&amp;nbsp; If you use 1 as the frequency and the payments are monthly then that is the monthly IRR.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt; 73         data _null_;
 74           array pmts[24] _temporary_ (24*100);
 75           * Calculate monthly IRR ;
 76           irr1 = irr(1,-800,of pmts[*]);
 77           * Calculate annual IRR ;
 78           irr12 = irr(12,-800,of pmts[*]);
 79           * Convert annual to monthly;
 80           irr1_2  = 100* ( (1 + irr12/100)**(1/12) -1 )  ;
 81           * Convert monthly to annual ;
 82           irr12_2 = 100* ( (1 + irr1/100)**12 -1 )  ;
 83           put (irr:) (=/);
 84         run;
 
 irr1=11.603264268
 irr12=273.35568521
 irr1_2=11.603264268
 irr12_2=273.35568521&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Mar 2026 14:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985413#M379848</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-03-26T14:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using REPEAT function to calculate IRR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985470#M379855</link>
      <description>&lt;P&gt;Thank you, Tom. This illustrates it very well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jit&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2026 17:43:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-REPEAT-function-to-calculate-IRR/m-p/985470#M379855</guid>
      <dc:creator>jitb</dc:creator>
      <dc:date>2026-03-26T17:43:27Z</dc:date>
    </item>
  </channel>
</rss>

