<?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 How to extract some data from correlation matrix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822158#M324630</link>
    <description>&lt;P&gt;Below is the lower triangle of my correlation matrix.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="superbug_0-1657228026014.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73040iD79AFD595EAF4A5B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="superbug_0-1657228026014.png" alt="superbug_0-1657228026014.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to extract the correlations that &amp;gt;0.2 but not equal 1 (I am not interested in the diagonal 1s). My matrix is 180 x 180. What's the SAS code/function that can let me quickly get what I need?&lt;/P&gt;
&lt;P&gt;Thanks much in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Jul 2022 21:10:41 GMT</pubDate>
    <dc:creator>superbug</dc:creator>
    <dc:date>2022-07-07T21:10:41Z</dc:date>
    <item>
      <title>How to extract some data from correlation matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822158#M324630</link>
      <description>&lt;P&gt;Below is the lower triangle of my correlation matrix.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="superbug_0-1657228026014.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73040iD79AFD595EAF4A5B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="superbug_0-1657228026014.png" alt="superbug_0-1657228026014.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to extract the correlations that &amp;gt;0.2 but not equal 1 (I am not interested in the diagonal 1s). My matrix is 180 x 180. What's the SAS code/function that can let me quickly get what I need?&lt;/P&gt;
&lt;P&gt;Thanks much in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2022 21:10:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822158#M324630</guid>
      <dc:creator>superbug</dc:creator>
      <dc:date>2022-07-07T21:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract some data from correlation matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822164#M324634</link>
      <description>&lt;P&gt;Assuming the correlation matrix is created by SAS (and your matrix looks like it is in Excel), this works fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/creating-a-table-of-highly-correlated-values/m-p/802045#M315701" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/creating-a-table-of-highly-correlated-values/m-p/802045#M315701&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just import the matrix from Excel, that code won't work without some changes, which I haven't bothered to figure out at this time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also I think you need to re-think this part&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to extract the correlations that &amp;gt;0.2 but not equal 1&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you do want off-diagonal terms that are equal to 1. Nevertheless, the method in that link works only on off-diagonal terms. And maybe (its up to you) you also want terms where the correlation is &amp;lt; –0.2.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2022 21:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822164#M324634</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-07T21:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract some data from correlation matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822265#M324693</link>
      <description>&lt;PRE&gt;options validvarname=v7;
proc import datafile='c:\temp\have.xlsx' out=have dbms=xlsx replace;run;

data temp;
 set have;
 n+1;
run;
proc transpose data=temp out=temp2;
by n A;
run;
data want;
 set temp2;
 if 0.2&amp;lt;col1&amp;lt;1;
 keep A _name_ col1;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jul 2022 13:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822265#M324693</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-07-08T13:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract some data from correlation matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822275#M324698</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As always, thanks a bunch!&lt;/P&gt;
&lt;P&gt;a big thumb up to your expertise!&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 13:52:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822275#M324698</guid>
      <dc:creator>superbug</dc:creator>
      <dc:date>2022-07-08T13:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract some data from correlation matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822284#M324703</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks so much for your code!&lt;/P&gt;
&lt;P&gt;Since I got my correlation matrix from another source, I need to read it into SAS.&lt;/P&gt;
&lt;P&gt;I applied your code, but the result I got only contains the correlation between the first and the last variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I run your example code step by step to check what appended in each step. My trial is as following&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc corr data=sashelp.class noprob nosimple outp=try;
    var age height weight;
/*    ods output pearsoncorr=corrs;*/
run;

data try1;
set try;
if _TYPE_="CORR";
run;

data try1;
set try1;
drop _TYPE_;
run;

data try2;
    set try1;
    length variable2 $ 32;
    array r _numeric_;
    do j=_n_+1 to dim(r);
        corr=r(j);
        variable2=vname(r(j));
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the result table I got is like the following. The corr column only contains the correlations from the last row.&amp;nbsp; I can't figure out how to fix that. Could you please give me direction? Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="superbug_0-1657290581339.png" style="width: 516px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73064i6479A9241C5DF854/image-dimensions/516x62?v=v2" width="516" height="62" role="button" title="superbug_0-1657290581339.png" alt="superbug_0-1657290581339.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 14:34:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822284#M324703</guid>
      <dc:creator>superbug</dc:creator>
      <dc:date>2022-07-08T14:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract some data from correlation matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822297#M324708</link>
      <description>&lt;P&gt;The code I gave works when you use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;ods output pearsoncorr=corrs;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead, you comment this out and add in&lt;FONT face="courier new,courier"&gt; outp=try&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;and now it doesn't work.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;So, the simple fix is to stop using &lt;FONT face="courier new,courier"&gt;outp=try&lt;/FONT&gt; and use&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;ods output pearsoncorr=corrs;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unless you have a VERY good reason for not wanting to use the code I gave , I'm not going to further try to debug your code.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 15:16:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822297#M324708</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-08T15:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract some data from correlation matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822301#M324710</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again for your time.&amp;nbsp; I learned a lot from your code.&lt;/P&gt;
&lt;P&gt;As I mentioned in my previous message. My correlation matrix was from another source, which saved as .csv.&amp;nbsp; I used SAS to read in. If I directly apply your code, I can only get the correlations of the last row. That's why I need to figure out each step of your code, so that I can apply it or modify it as needed.&lt;/P&gt;
&lt;P&gt;I very much appreciate your help and expertise! Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 15:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822301#M324710</guid>
      <dc:creator>superbug</dc:creator>
      <dc:date>2022-07-08T15:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract some data from correlation matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822320#M324716</link>
      <description>&lt;P&gt;You need to provide a portion of this CSV file, perhaps a 4x4 matrix. You need to follow these instructions: import the CSV file into SAS, and then turn it into SAS data step code via &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;this macro&lt;/A&gt; and then post the code. Or you can create as &lt;FONT color="#FF0000"&gt;working&lt;/FONT&gt; SAS data step code by typing it in yourself (please test the code before you post it so that you know it works). Do not attach the .csv file because I never download attachments.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 17:38:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-some-data-from-correlation-matrix/m-p/822320#M324716</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-08T17:38:40Z</dc:date>
    </item>
  </channel>
</rss>

