BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Deva_123
Calcite | Level 5

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 -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;

 

Desired output :

-26

44

34

-85

65

-56

43

21

7

21

 

But I am getting output as :

-26
44
34
-85
26
0
65
-56
43
-44
-65
0
21
7
-34
56
-21
0
21
85
-43
-7
-21
0

 

 

Please help me!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
koyelghosh
Lapis Lazuli | Level 10

@Deva_123I just reshaped it into a square matrix (5x5) and got the output as below.

 

OutputOutput

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

Ksharp
Super User

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
Deva_123
Calcite | Level 5

Thanks a lot for your quick reply! This is working perfectly!

 

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1158 views
  • 2 likes
  • 4 in conversation