Reputation: 3938
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
Upvotes: 0
Views: 4088
Reputation: 63424
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;
Upvotes: 2