<?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 create a table of correlations for many subgroups? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/294864#M60091</link>
    <description>&lt;P&gt;Dear all SAS experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to have a table of correlation between two variables (for example, x and y) by many groups. My dream matrix would like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GroupNumber &amp;nbsp; &amp;nbsp; &amp;nbsp;Correlation between x and y&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.&lt;SPAN&gt;5153&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.6&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.3&lt;/P&gt;&lt;P&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.6&lt;/P&gt;&lt;P&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can use BY statement in PROC CORR procedures, but I would get many seperate tables for each subgroup in the BY variable like below (an example result for groupNumber 1), and it's time consuming to build my dream table by hand since it comprosed of more than 100 sugroups each year.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Pearson Correlation Coefficients, N = 8996452&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Prob &amp;gt; |r| under H0: Rho=0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0.5153&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;0.5153&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions would be appreciated!&lt;/P&gt;</description>
    <pubDate>Mon, 29 Aug 2016 15:37:14 GMT</pubDate>
    <dc:creator>huhuhu</dc:creator>
    <dc:date>2016-08-29T15:37:14Z</dc:date>
    <item>
      <title>How to create a table of correlations for many subgroups?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/294864#M60091</link>
      <description>&lt;P&gt;Dear all SAS experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to have a table of correlation between two variables (for example, x and y) by many groups. My dream matrix would like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GroupNumber &amp;nbsp; &amp;nbsp; &amp;nbsp;Correlation between x and y&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.&lt;SPAN&gt;5153&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.6&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.3&lt;/P&gt;&lt;P&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.6&lt;/P&gt;&lt;P&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can use BY statement in PROC CORR procedures, but I would get many seperate tables for each subgroup in the BY variable like below (an example result for groupNumber 1), and it's time consuming to build my dream table by hand since it comprosed of more than 100 sugroups each year.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Pearson Correlation Coefficients, N = 8996452&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Prob &amp;gt; |r| under H0: Rho=0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0.5153&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;0.5153&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions would be appreciated!&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 15:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/294864#M60091</guid>
      <dc:creator>huhuhu</dc:creator>
      <dc:date>2016-08-29T15:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table of correlations for many subgroups?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/294878#M60094</link>
      <description>&lt;P&gt;This will give you a table (corr) of all of the coefficients. You'll just need to eliminate the redundant ones.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc corr data = sashelp.iris;
var petallength sepallength;
by species;
ods output pearsonCorr = Corr; 
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;hope this helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ray&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 16:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/294878#M60094</guid>
      <dc:creator>rayIII</dc:creator>
      <dc:date>2016-08-29T16:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table of correlations for many subgroups?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/295045#M60101</link>
      <description>&lt;PRE&gt;
Want IML code ?



proc iml;
use sashelp.iris nobs nobs;
read all var{species petallength sepallength};
close;

start_end=t( loc(t(species) ^= ' '||remove(species,nobs)) )||
          t( loc(t(species) ^= remove(species,1)||' ') );

group=species[start_end[,1]];
corr=j(nrow(group),1,.);
do i=1 to nrow(group);
 idx=start_end[i,1]:start_end[i,2]; 
 temp=petallength[idx]|| sepallength[idx];
 corr[i]=corr(temp)[2];
end;
create want from corr[r=group c={corr}];
append from corr[r=group];
close;
quit;

proc print noobs;run;



OUTPUT:

group	CORR
Setosa	0.26718
Versicolor	0.75405
Virginica	0.86422

&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Aug 2016 04:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/295045#M60101</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-30T04:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table of correlations for many subgroups?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/295125#M60104</link>
      <description>&lt;P&gt;You can use the NOPRINT and OUT= options to suppress the tables and create a SAS data set that contains the correlations. Then use a DATA step or a WHERE clause to subset the output statistics:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc corr data = sashelp.iris noprint 
          out=outCorr(where=(_TYPE_="CORR"));
by species;
var petallength sepallength;
run; 

proc print data=outCorr label;
where _NAME_="PetalLength";  /* var1 */
var Species                  /* BY var */
    SepalLength;             /* var2 */
label SepalLength="Corr(PetalLength, SepalLength)";
run;
&lt;/CODE&gt;&lt;/PRE&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>Tue, 30 Aug 2016 12:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/295125#M60104</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-08-30T12:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table of correlations for many subgroups?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/295144#M60107</link>
      <description>&lt;PRE&gt;
Rick,
It could be simple as :


proc corr data = sashelp.iris noprint 
          out=outCorr(where=(_TYPE_="CORR"));
by species;
var petallength ;
with sepallength;
run; 
proc print noobs;run;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Aug 2016 13:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/295144#M60107</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-30T13:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table of correlations for many subgroups?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/295965#M60172</link>
      <description>&lt;P&gt;Thank you, that's the dream output I like to have!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 18:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/295965#M60172</guid>
      <dc:creator>huhuhu</dc:creator>
      <dc:date>2016-09-01T18:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table of correlations for many subgroups?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/295966#M60173</link>
      <description>&lt;P&gt;Thank you very much! That's even simpler!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 18:46:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/295966#M60173</guid>
      <dc:creator>huhuhu</dc:creator>
      <dc:date>2016-09-01T18:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table of correlations for many subgroups?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/295967#M60174</link>
      <description>&lt;P&gt;Thank you for your help&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 18:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-table-of-correlations-for-many-subgroups/m-p/295967#M60174</guid>
      <dc:creator>huhuhu</dc:creator>
      <dc:date>2016-09-01T18:54:51Z</dc:date>
    </item>
  </channel>
</rss>

