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!
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;
I think you forgot to post your question?
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;
Looks perfect!
Let me try it on real data.
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.
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.
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).
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...
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!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.