Statistical programming, matrix languages, and more

matrix Product by IML

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

matrix Product by IML

data a;

input investor $ y;

cards;

fdcd1 0.006157039

fdcd2 0.001510721

fdcd3 0.35458659

fdcd4 -0.04071315

fdcd5 -0.01494467

fdcd6   -0.009

run;

The matrix is like this( Note: the colname of matrix is a mess of vector. Their orders are different).  How to give their Product?  Thanks!

fdcd1 fdcd3 fdcd2 fdcd5 fdcd4 fdcd6

0.79 0.01 1.09 3.75 0.82 0.43

1.4 0.23 0.86 0.88 1.44 1.19

0 0 0 0 0 0

0 0.09 0 0 0 0.02

0.33 0 0 0 0.33 0.29

0.28 0 0 0 0.27 0.42

0 0 0 0 0 0

0 0 0 0 0 0.04

0 0 0 0 0 0

0.14 0.19 0 0 0.14 0.1

0 0 0 0 0 0

0.19 0 0 0 0.19 0.17

0 0 0 0 0 0

0.12 0.1 0 0 0.12 0.15

0 0 0 0 0 0.06

0 0 0 0 0 0

0.1 0 0 0 0.1 0.09


Accepted Solutions
Solution
‎02-02-2015 10:41 AM
SAS Super FREQ
Posts: 3,221

Re: matrix Product by IML

It looks like you want the product of the matrix (in the second part) with the vector (in the first part). The problem you are having is that the columns of the matrix are not in the same order as the elements in the vector.

Read in the investors and the y vector from data set A.  Then use the INVESTORS vector to specify the order of the variables when you read the matrix, which I assume is in a data set named M:

proc iml;
use a;
read all var {investor y};
close a;

use m;
read all var investor into X;  /* read variables in order contained in INVESTOR */
close m;

v = X*y;   /* matrix-vector product */
print v;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,270

Re: matrix Product by IML

Normally I think of the "matrix product" as the multiplication of two (or more) matrices, but you only seem to have one matrix. Could you explain further what you want?

Solution
‎02-02-2015 10:41 AM
SAS Super FREQ
Posts: 3,221

Re: matrix Product by IML

It looks like you want the product of the matrix (in the second part) with the vector (in the first part). The problem you are having is that the columns of the matrix are not in the same order as the elements in the vector.

Read in the investors and the y vector from data set A.  Then use the INVESTORS vector to specify the order of the variables when you read the matrix, which I assume is in a data set named M:

proc iml;
use a;
read all var {investor y};
close a;

use m;
read all var investor into X;  /* read variables in order contained in INVESTOR */
close m;

v = X*y;   /* matrix-vector product */
print v;

New Contributor
Posts: 4

Re: matrix Product by IML

Thanks for your help.

Post a Question
Discussion Stats
  • 3 replies
  • 380 views
  • 0 likes
  • 3 in conversation