<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Combine Pearson and Spearman correlations in one matrix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-Pearson-and-Spearman-correlations-in-one-matrix/m-p/833829#M329657</link>
    <description>&lt;P&gt;I like KSharp's solution. It can be shortened by using a 0/1 mask to form the upper/lower parts of the matrix, rather than using indices:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
run;

proc iml;
use have;
read all var _num_ into x[c=vname];
close;

pearson=corr(x,'pearson');
spearman=corr(x,'spearman');
IsUpper = (row(pearson)&amp;gt;col(pearson));
want = IsUpper#Pearson + ^IsUpper#Spearman;

print want[c=vname r=vname l='Correlations: Lower=Pearson; Upper=Spearman'];
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 16 Sep 2022 12:39:54 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2022-09-16T12:39:54Z</dc:date>
    <item>
      <title>Combine Pearson and Spearman correlations in one matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Pearson-and-Spearman-correlations-in-one-matrix/m-p/833658#M329574</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there a way to calculate both Spearman and Pearson correlation and combine them in one table?&lt;BR /&gt;In academic papers, I often see tables with e.g. Pearson correlation below the diagonal and Spearman above the diagonal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I'm doing as of now, but I'm unsure how to put it together like described above:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;Proc Corr data = have Pearson Spearman OUTP=P_test OUTS=S_test;
	Var Var_1 Var_2 Var_3;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This of course gives me two tables - what I would like is just one table with both Spearman and Pearson.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 16:08:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Pearson-and-Spearman-correlations-in-one-matrix/m-p/833658#M329574</guid>
      <dc:creator>drip_</dc:creator>
      <dc:date>2022-09-15T16:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Pearson and Spearman correlations in one matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Pearson-and-Spearman-correlations-in-one-matrix/m-p/833666#M329577</link>
      <description>&lt;P&gt;I am not sure what the word "combine" means to you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What it means to me is something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    length type $ 8;
    set p_test(in=in1) s_test(in=in2);
    where _type_='CORR';
    if in1 then type='Pearson';
    if in2 then type='Spearman';
    drop _type_ _name_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really need pearson above the diagonal and spearman below the diagonal, that could be done with the merge statement and arrays. But I would encourage you to not do that; the output from the code above is completely clear and useful, while the output of Pearson above the diagonal and Spearman below the diagonal leads to confusion as the viewer has to stop and think and remember which is above the diagonal and which is below, and potentially get it wrong.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 16:58:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Pearson-and-Spearman-correlations-in-one-matrix/m-p/833666#M329577</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-15T16:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Pearson and Spearman correlations in one matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Pearson-and-Spearman-correlations-in-one-matrix/m-p/833821#M329652</link>
      <description>&lt;P&gt;It is a SAS/IML thing. I think &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt; would like this kind of matrix very much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
run;

proc iml;
use have;
read all var _num_ into x[c=vname];
close;

pearson=corr(x,'pearson');
pearson[loc(row(pearson)&amp;lt;col(pearson))]=0;

spearman=corr(x,'spearman');
spearman[loc(row(spearman)&amp;gt;col(spearman))]=0;

want=pearson+spearman-diag(pearson);
print want[c=vname r=vname l=''];
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1663329334641.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75314i473CFF6C8AB093A8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1663329334641.png" alt="Ksharp_0-1663329334641.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 11:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Pearson-and-Spearman-correlations-in-one-matrix/m-p/833821#M329652</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-09-16T11:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Pearson and Spearman correlations in one matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Pearson-and-Spearman-correlations-in-one-matrix/m-p/833829#M329657</link>
      <description>&lt;P&gt;I like KSharp's solution. It can be shortened by using a 0/1 mask to form the upper/lower parts of the matrix, rather than using indices:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
run;

proc iml;
use have;
read all var _num_ into x[c=vname];
close;

pearson=corr(x,'pearson');
spearman=corr(x,'spearman');
IsUpper = (row(pearson)&amp;gt;col(pearson));
want = IsUpper#Pearson + ^IsUpper#Spearman;

print want[c=vname r=vname l='Correlations: Lower=Pearson; Upper=Spearman'];
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Sep 2022 12:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Pearson-and-Spearman-correlations-in-one-matrix/m-p/833829#M329657</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-09-16T12:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Pearson and Spearman correlations in one matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Pearson-and-Spearman-correlations-in-one-matrix/m-p/833858#M329674</link>
      <description>&lt;P&gt;Thanks everyone!&lt;/P&gt;&lt;P&gt;Ksharp and Rick, your solutions worked for me - thanks to PaigeMiller for your input as well.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 14:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Pearson-and-Spearman-correlations-in-one-matrix/m-p/833858#M329674</guid>
      <dc:creator>drip_</dc:creator>
      <dc:date>2022-09-16T14:07:33Z</dc:date>
    </item>
  </channel>
</rss>

