Hi All,
I am trying extract upper triangular elements using SAS/IML, I am getting the result incorrectly.
proc iml;corr = {0 -26 44 34 -8526 0 65 -56 43-44 -65 0 21 7-34 56 -21 0 2185 -43 -7 -21 0};r = row(corr);c = col(corr);upperTri = loc(r < c);v = corr[upperTri];print v;
Desired output :
-26
44
34
-85
65
-56
43
21
7
But I am getting output as :
Please help me!
I think this identifies the problem
proc iml; corr = {0 -26 44 34 -85 26 0 65 -56 43 -44 -65 0 21 7 -34 56 -21 0 21 85 -43 -7 -21 0}; print corr;show corr;
View solution in original post
@Deva_123I just reshaped it into a square matrix (5x5) and got the output as below.
Output
The code is as below.
proc iml; corr = {0 -26 44 34 -85 26 0 65 -56 43 -44 -65 0 21 7 -34 56 -21 0 21 85 -43 -7 -21 0}; corr = shape(corr,5); r = row(corr); c = col(corr); upperTri = loc(r < c); v = corr[upperTri]; print v; run;
Best wishes
Paige is right. You missed comma ',' .
And why not post it at IML forum ?
proc iml; corr = {0 -26 44 34 -85 , 26 0 65 -56 43 , -44 -65 0 21 7 , -34 56 -21 0 21 , 85 -43 -7 -21 0}; r = row(corr); c = col(corr); upperTri = loc(r < c); v = corr[upperTri]; print v; quit;
OUTPUT:
v -26 44 34 -85 65 -56 43 21 7 21
Thanks a lot for your quick reply! This is working perfectly!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.