我有以下代码在MATLAB和I中运行良好,可以在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中,我只是将其留空
答案 0 :(得分:2)
您应该正确指定它。 A [rows,]表示A的所有列,而不仅仅是任意数量的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;