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

Dear friends, consider correlation matrix (attached) and variables IBS_A, IBS_B and IBS_C. This is short example. I usually have much larger matrices with mostly unknown number of variables (goal is to have universal solution). I would like to obtain a vector "New" which would use data without diagonal and duplicates. 

New

0,5

0,625

0,5

This is actually corelation between ab, ac, and ac. other is surplus. Can this be done?

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
proc iml;
use sashelp.class;
read all var _num_ into x;
close;
corr=corr(x);
idx=loc(row(corr)>col(corr));
want=unique(corr[idx]);
print corr ,want;
quit;

View solution in original post

9 REPLIES 9
PeterClemmensen
Tourmaline | Level 20

I think you forgot to post your question?

MajaAGR
Obsidian | Level 7
Actually I started to write and in the process my mother called... Total mess 😉
Ksharp
Super User
proc iml;
use sashelp.class;
read all var _num_ into x;
close;
corr=corr(x);
idx=loc(row(corr)>col(corr));
want=unique(corr[idx]);
print corr ,want;
quit;
MajaAGR
Obsidian | Level 7

Looks perfect!

Let me try it on real data. 

MajaAGR
Obsidian | Level 7
Works awesome!
You saved hours of my life.

Thanks!
Rick_SAS
SAS Super FREQ

See the article "Extract the lower triangular elements of a matrix," which defines a function called StrictLowerTriangular.

 

If you also want to get the pairs of variable names for each entry, see the code in this blog post about pairwise correlations.

IanWakeling
Barite | Level 11

I think KSharp's code will work for you, but you may want to remove the call to UNIQUE as it will give you a vector with the correlation coefficients sorted into order - which you may not want.  It will also remove duplicates if there are any.

MajaAGR
Obsidian | Level 7

Hi!

For the moment it looks OK.

I removed unwanted parts and i am checking on few files will I get all values.

Order is not important for now, because all I want to do later is to plot box plots from multiple matrices. This is actually genomic relationship matrix for one population and those values and its variance will be compared (via box plot) with another population.

So order is not important. Just unique pairs (a-c is fine, c-a is exactly the same, and diagonal must be one). 

MajaAGR
Obsidian | Level 7

Hi!

Thanks!

I knew about StrictLowerTriangular but this "unique" part was an issue. It is easy with 5-10 animals but with 1000 and more...

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 9 replies
  • 1106 views
  • 5 likes
  • 5 in conversation