BookmarkSubscribeRSS Feed
Marcos
Calcite | Level 5
Hello,

I'm trying to use the FINANCE('XIRR'....) function within the IML (must perform many interactions, so IML is the best place), however, I cannot get it to work. I understand can be done in a Data Step, by transposing the data etc, however, we must run so many loops that the data step option will take to long, Here are two sample codes, trying to load the values from a table on this function, none of these work, any suggestion?

Thanks, Marcos.



/* Test 1 */
data test;
v1 = -10000;
v2 = 2750;
v3 = 4250;
v4 = 3250;
v5 = 2750;
d1 = mdy(1,1,2008);
d2 = mdy(3,1,2008);
d3 = mdy(10,30,2008);
d4 = mdy(2,15,2009);
d5 = mdy(4,1,2009);
/*r = finance('xirr', v1, v2, v3, v4, v5, d1, d2, d3, d4, d5, 0.1);
put r = ;*/
run;


proc iml;

use test;
read all var _ALL_ into test;

values=test[1,];

r=finance('xirr',values, 0.5);


print r;

quit;




/* Test 2 */
data test2;
v1 = -10000;
d1 = mdy(1,1,2008);
output;
v2 = 2750;
d2 = mdy(3,1,2008);
output;
v3 = 4250;
d3 = mdy(10,30,2008);
output;
v4 = 3250;
d4 = mdy(2,15,2009);
output;
v5 = 2750;
d5 = mdy(4,1,2009);
output;
run;


proc iml;

use test2;
read all var _ALL_ into test;

values=test[,1];
dates=test[,2];

print dates;

r=finance('xirr',values, dates, 0.5);
print r;
quit;
1 REPLY 1
Rick_SAS
SAS Super FREQ
Yes, this can be tricky. I need to write a blog post about this (http://blogs.sas.com/iml), since several people have asked a similar question.

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.

The trick is to convert the vector of values into a comma-delimted string, and then stick the string into a macro variable by using the SYMPUT function. (This technique appears in my book Statistical Programming with SAS/IML Software: http://support.sas.com/publishing/authors/wicklin.html)

The following statements define a SAS/IML module called GetArgList that taks a vector of values and creates a comma-delimited string from it. You can then stick that string into the macro &myArgs, and use it in the FINANCE function:

proc iml;
start GetArgList(v);
/* convert numeric elements to a single string */
y = strip(putn(rowvec(v),"BEST12.")) + ",";
/* get rid of last comma */
y[ncol(y)] = strip(putn(v[ncol(y)],"BEST12."));
return( rowcat(y) ); /* scalar string */
finish;

use test;
read all var _ALL_ into values;

call symput("myArgs", GetArgList(values));
r = finance('xirr', &myArgs, 0.1);
print r;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 1 reply
  • 915 views
  • 0 likes
  • 2 in conversation