hi Rick, i solved it! not very pretty but it works. Here is your code with comments on how i understand it. Please let me know if its OK to concatenate M to s when reading do loop result into subscripts. Many thanks in advance! proc iml; use corr; read all var _NUM_ into X[c=varNames]; close corr; diagIdx = do(1, nrow(X)*ncol(X), ncol(x)+1); *change all diagonal 1s; x[diagIdx] = .; *to missing; start ind2sub( p, ind ); *declare function to determine row and column for max corr; idx = colvec(ind); n = nrow(idx); col = 1 + mod(idx-1, p); row = 1 + (idx-col) / p; return ( row || col ); finish; start PairCorr(x); *declare function to pick pairs of vars with max corrs; y = x; /*copy of the corr matrix. We'll overwrite this with missing values */ k = floor(ncol(x)/2); *calculate number of pairs; subscripts = j(k,3); *create matrix to store results of do loop; do i = 1 to k; M=max(y); s = ind2sub(ncol(y), y[<:>]); *call function get (row col) directly without looping; y[ s, ] = .; *set row with used up corr to missing; y[ , s] = .; *set column with used up corr to missing; subscripts[i,] = s || M; *here i am not sure if i am doing it correctly; end; return( subscripts ); finish; pc = PairCorr(x); results = varNames[ pc[,1] ] || varNames[ pc[,2] ] || char(pc[,3]); *here is also a question mark about if it is ok to convert value to character and use it; print results; create pairs from results; append from results; *saved data looks good and I am happy with the result. quit;
... View more