0

I have the following code that works great in MATLAB and I which to transpose in SAS/PROC IML:

[row col] = size(coeff);

A_temp    = zeros(row,col);
for i = 1: row/6            
    A_temp(6*(i-1)+1:6*i,:) = coeff(6*(i-1)+1:6*i,4:col);end;

In Proc IML I do the following:

proc iml;
  use i.coeff;
  read all var {...} into coeff;
  print coeff;

row=NROW(coeff);
print row;
col=NCOL(coeff);
print col;
A_temp=J(row,col,0); *create zero matrix;
print A_temp;

Do i=1 TO row/6;
A_temp[(6*(i-1)+1):(6*i),]=coeff[(6*(i-1)+1):(6*i),(4:col)];
END;
quit;

The code breaks down at the DO loop "(execution) Matrices do not conform to the operation. "...why? If I understand correctly in PROC IML if I wish to select all column (in MATLAB this would be ":") but in SAS IML I simply leave it blank

Joe
  • 62,789
  • 6
  • 49
  • 67
Plug4
  • 3,838
  • 9
  • 51
  • 79
  • What exactly are you trying to do at the end there? It looks like you're trying to assign a [6 rows, 4:col] matrix to a [6 rows, 1:col] matrix. How's that going to work exactly - what happens to the other 3 columns of the A_temp matrix? – Joe Mar 20 '13 at 18:26
  • my A_temp is a 30X30 matrix with zeros prior to the loop. Then I select from the COEFF matrix 6 rows and 26columns to be put in the A_temp matrix...if it works in MATLAB..how different can this be in IML? Thanks – Plug4 Mar 20 '13 at 18:37
  • What I mean, is that you're putting a 6x27 (4:30 is 27) matrix and placing it in a 6x30 matrix (the defined subset of A_temp). What is SAS supposed to do there? Obviously Matlab just puts it in the first 27, but how is SAS supposed to know that is what you want (as opposed to the last 27 or something else)? – Joe Mar 20 '13 at 18:41

1 Answers1

2

You should specify it correctly. A[rows,] means ALL columns of A, not just any number of them. See this simplified example:

proc iml;
/*  use i.coeff;
  read all var {...} into coeff;
  print coeff;
*/
coeff = J(15,10,3);
row=NROW(coeff);
print row;
col=NCOL(coeff);
print col;
A_temp=J(row,col,0); *create zero matrix;
print A_temp;

Do i=1 TO row;
* does not work; *A_temp[i,]=coeff[i,(4:col)];
A_temp[i,1:col-3]=coeff[i,(4:col)];
END;
quit;
Joe
  • 62,789
  • 6
  • 49
  • 67