Sometime I need to remove zeros in a covariance matrix in order to calculate eigenvalues of the sub-matrix. Here is an utility to remove the corresponding rows and columns of zeros.
proc iml;
b={1 0 3 0 5,
0 0 0 0 0,
1 0 3 0 5,
0 0 0 0 0,
1 0 3 0 5}
;
start remove_rows_cols(a);
***a must be a square matrix**;
n=nrow(a);
nzero=ncol(loc(a[1:5]=0));
idx=loc(a=0);
return (shape(remove(a,idx),n-nzero,n-nzero));
finish;
c=remove_rows_cols(b);
print b c;
quit;