How can I extract lower triangular of a matrix? VECH or SYMSQR functions exports elements in column order but I want exactly the triangular shape.
It worked. When I modify it to my matrix I don't get my matrix's column and rows.What am I missing here?
read all var _NUM_ into my_matrix;
UpperIdx = loc(row(my_matrix) < col(my_matrix));
Actually, I'm working on the code you wrote. I have candidates id's in the columns and rows. I want to have candidates id's in the triangular matrix. there is output of results in the attachment.
use tr; read all var _ALL_; close tr;
X=j(ncol(Cand), ncol(Cand), .);
do i=1 to nrow(rt);
/* replace missing values with 0 */
missIdx = loc(X=.); /* locations of missing values */
nonmissIdx = loc(X^= ); /* locations of nonmissing values */
X[missIdx] = 0.5; /* replace missing with 0 */
Z = X; /* make a copy */
Z[nonmissIdx] = .; /* replace orig probs with missing */
X = X + Z`; /* use missing values for lower triangular probabilities */
print X[colName=((Cand)) rowName=((Cand))];
create matrix from X [colname=Cand rowname=Cand];
append from X[rowname=Cand];
read all var _NUM_ into matrix;
UpperIdx = loc(row(matrix) < col(matrix));
On the READ statement, use the ROWNAME= option to also read the IDs:
proc iml; use matrix; read all var _NUM_ into matrix[rowname=Cand]; close; UpperIdx = loc(row(matrix) < col(matrix)); LowerTr=matrix; LowerTr[UpperIdx]=0; print LowerTr[rowname=Cand colname=Cand];
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.