0

我有以下代码在 MATLAB 中运行良好,我可以在 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;

在 Proc IML 中,我执行以下操作:

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;

代码在 DO 循环处发生故障“(执行)矩阵不符合操作。”......为什么?如果我在 PROC IML 中理解正确,如果我希望选择所有列(在 MATLAB 中这将是“:”),但在 SAS IML 中我只是将其留空

4

1 回答 1

2

您应该正确指定它。A[rows,] 表示 A 的所有列,而不是任意数量的列。请参阅此简化示例:

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;
于 2013-03-20T18:43:14.940 回答