0

I have data set named input_data below import from EXCEL.

0.353481635 0.704898683 0.078640917 0.813815803 0.510842666 0.240912872 0.986312218 0.781868961 0.682272971
0.443441526 0.653187181 0.753981865 0.34909803  0.84215961  0.793863082 0.047816942 0.176759112 0.54213244
0.21443281  0.142501578 0.927011587 0.407251043 0.290280445 0.90730524  0.677030212 0.770541244 0.915728969
0.583493041 0.685127614 0.119042255 0.067769934 0.795793907 0.405029459 0.817724346 0.594170688 0.345660875
0.816193304 0.636823417 0.036348358 0.027985453 0.117027493 0.436516667 0.593191955 0.916981676 0.574223091
0.766842249 0.743249552 0.400052263 0.809650253 0.683610082 0.42152573  0.050520292 0.329441952 0.868549022
0.112847881 0.462579082 0.526220066 0.320851313 0.944585551 0.233027402 0.66141107  0.8380858   0.120044416
0.873949265 0.118525986 0.590234323 0.481974796 0.668976582 0.466558592 0.934633956 0.643438048 0.053508922

And I have another data set called p below

data p;
input p;
datalines;
0.12    
0.23    
0.11    
0.49    
0.52    
0.78    
0.8 
0.03    
0.02
run;

proc transpose data = p out=p2;
run;

What I want to do is matrix manipulation in IML using SAS.

I have some code already, but the final calculation got error. Can someone give me a hand?

proc iml;
use input_data;
read all var _num_ into x; 
print x;

proc iml;
use p2;
read all var _num_ into k;
print k;

proc iml;
Value1 = k * x;  
print Value1;
quit;
Joe
  • 62,789
  • 6
  • 49
  • 67
Elif Y
  • 251
  • 1
  • 4
  • 21
  • Looks like you have an 8x9 matrix and a 1x9 matrix so you can't multiply those two as they stand. You would need to transpose one of them so it was 8x9 * 9x1. This is assuming you want the dot product of the matrices. Skip the transpose step and it should be okay. – Joe Oct 10 '14 at 17:12
  • even I remove transpose, it shows x 0 row 0 col (type ?, size 0) kpd 0 row 0 col (type ?, size 0) – Elif Y Oct 10 '14 at 17:46
  • Also in the future use the [tag:sas-iml] tag, not only because this is about iml, but Rick answers those sometimes faster than myself and definitely more knowledgeable for the harder IML questions. – Joe Oct 10 '14 at 17:56

1 Answers1

3

You have several problems here.

First off, you have three PROC IML statements. PROC IML only persists values while it's running; once it quits, all of the vectors go away forever. So remove the PROC IMLs.

Second, you need to make sure your matrices are correctly ordered and structured. Matrix multiplication works by the following:

m x n * n x p = m x p

Where both N's must be the same. This is rows x columns, so the left-side matrix must have the same number of columns as the right-side matrix has rows. (This is because each element of each row on the left-side matrix is multiplied by the corresponding element in the column on the right-side matrix and then summed, so if the numbers don't match it's not possible to do.)

So you have 8x9 and 9x1, which you transpose to 1x9. So first off, don't transpose p, leave it 9x1. Then, make sure you have the order right (matrix multiplication is NOT commutative, the order matters). k * x means 9x1 * 8x9 which doesn't work (since 1 and 8 aren't the same - remember, the inner two numbers have to match.) x*k does work, since that is 8x9 * 9x1, the two 9s match.

Final output:

proc iml;
  use input_data;
  read all var _num_ into x; 
  print x;

  use p;
  read all var _num_ into k;
  print k;


  Value1 = x * k;  
  print Value1;
quit;
Joe
  • 62,789
  • 6
  • 49
  • 67