<?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: Combining 2 correlation tables into 1.  (1 above, 1 below the diagonal) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combining-2-correlation-tables-into-1-1-above-1-below-the/m-p/835457#M330299</link>
    <description>&lt;P&gt;This works with the example data:&lt;/P&gt;
&lt;PRE&gt;data want;
   merge temp1
         temp2 (rename=(var1=v1 var2=v2 var3=v3 var4=v4))
   ; 
   by col1;
   select (upcase(col1));
      when('VAR1') do;  var1=.; 
                   end;
      when('VAR2') do;  var2=.;
                        var1=v1;
                   end;
      when('VAR3') do;  var3=.;
                        var1=v1;
                        var2=v2;
                   end;
      when('VAR4') do;  var4=.;
                        var1=v1;
                        var2=v2;
                        var3=v3;
                   end;
      otherwise;
   end;
   keep col1 var: ;
run;
&lt;/PRE&gt;
&lt;P&gt;Depending on your actual variable names you may have to use the NOTSORTED option on the BY Col1 ; statement.&lt;/P&gt;
&lt;P&gt;SELECT, if you have not seen that before is a way to do a bunch of If value= do this. In this form the WHEN is a single value for the row indicator. I use an UPCASE function on the COL1 variable just in case the case of the variable is inconsistent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is pretty much a code equivalent of look at row1 and select the values to put in the columns, then row2 etc. This can get pretty cumbersome if you have 50 variables involved though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Sep 2022 16:18:02 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-09-27T16:18:02Z</dc:date>
    <item>
      <title>Combining 2 correlation tables into 1.  (1 above, 1 below the diagonal)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-2-correlation-tables-into-1-1-above-1-below-the/m-p/835452#M330296</link>
      <description>&lt;P&gt;I am using SAS EG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given 2 tables similar to the following Temp1 and Temp2.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Temp1;
input Col1 $4. Var1 Var2 Var3 Var4 5.2;
datalines;
Var1  1.0 0.45 0.22 0.89
Var2 0.45 1.0 0.54 0.94
Var3 0.22 0.54 1.0 0.33
Var4 0.89 0.94 0.33 1.0 
;
run;

data Temp2;
input Col1 $4. Var1 Var2 Var3 Var4 5.;
datalines;
Var1 0 213 17 409
Var2 213 0 78 55
Var3 17 78 0 300
Var4 409 55 300 0 
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is there a way to combine the 2 tables with one set of data being above the diagonal, and the other below?&amp;nbsp; as in the above table "Combined".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've read a few posts along these lines that require SAS/IML. But i do not have access to IML.&amp;nbsp; Is it possible without IML?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 15:23:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-2-correlation-tables-into-1-1-above-1-below-the/m-p/835452#M330296</guid>
      <dc:creator>mcook</dc:creator>
      <dc:date>2022-09-27T15:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: Combining 2 correlation tables into 1.  (1 above, 1 below the diagonal)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-2-correlation-tables-into-1-1-above-1-below-the/m-p/835453#M330297</link>
      <description>&lt;P&gt;I forgot to add the "Combined" Table example above.. Apologies&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Combined;
input Col1 $4. Var1 Var2 Var3 Var4 5.2;
datalines;
Var1 . 0.45 0.22 0.89
Var2 213 . 0.54 0.94
Var3 17 78 . 0.33
Var4 409 55 300 . 
;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Sep 2022 15:24:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-2-correlation-tables-into-1-1-above-1-below-the/m-p/835453#M330297</guid>
      <dc:creator>mcook</dc:creator>
      <dc:date>2022-09-27T15:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Combining 2 correlation tables into 1.  (1 above, 1 below the diagonal)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-2-correlation-tables-into-1-1-above-1-below-the/m-p/835456#M330298</link>
      <description>&lt;P&gt;Just use arrays.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data above;
  input Col1 $ Var1-Var4 ;
datalines;
Var1  1.0 0.45 0.22 0.89
Var2 0.45 1.0 0.54 0.94
Var3 0.22 0.54 1.0 0.33
Var4 0.89 0.94 0.33 1.0 
;

data below ;
  input Col1 $ Var1-Var4 ;
datalines;
Var1 0 213 17 409
Var2 213 0 78 55
Var3 17 78 0 300
Var4 409 55 300 0 
;


data want ;
  merge below above(rename=(var1-var4=above1-above4));
  by col1;
  array var [4];
  array above [4];
  var[_n_] = .;
  do index=_n_+1 to dim(var);
    var[index]=above[index];
  end;
  drop index above1-above4 ;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    Col1    var1     var2      var3    var4

 1     Var1       .     0.45      0.22    0.89
 2     Var2     213      .        0.54    0.94
 3     Var3      17    78.00       .      0.33
 4     Var4     409    55.00    300.00     .

&lt;/PRE&gt;
&lt;P&gt;PS Do not use a decimal width on an informat unless you know that the strings you are reading from were purposely built without an explicit decimal to save one byte.&amp;nbsp; Otherwise strings without periods will be divided by that number of powers of 10 to move the decimal place to the implied position.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 16:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-2-correlation-tables-into-1-1-above-1-below-the/m-p/835456#M330298</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-27T16:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Combining 2 correlation tables into 1.  (1 above, 1 below the diagonal)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-2-correlation-tables-into-1-1-above-1-below-the/m-p/835457#M330299</link>
      <description>&lt;P&gt;This works with the example data:&lt;/P&gt;
&lt;PRE&gt;data want;
   merge temp1
         temp2 (rename=(var1=v1 var2=v2 var3=v3 var4=v4))
   ; 
   by col1;
   select (upcase(col1));
      when('VAR1') do;  var1=.; 
                   end;
      when('VAR2') do;  var2=.;
                        var1=v1;
                   end;
      when('VAR3') do;  var3=.;
                        var1=v1;
                        var2=v2;
                   end;
      when('VAR4') do;  var4=.;
                        var1=v1;
                        var2=v2;
                        var3=v3;
                   end;
      otherwise;
   end;
   keep col1 var: ;
run;
&lt;/PRE&gt;
&lt;P&gt;Depending on your actual variable names you may have to use the NOTSORTED option on the BY Col1 ; statement.&lt;/P&gt;
&lt;P&gt;SELECT, if you have not seen that before is a way to do a bunch of If value= do this. In this form the WHEN is a single value for the row indicator. I use an UPCASE function on the COL1 variable just in case the case of the variable is inconsistent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is pretty much a code equivalent of look at row1 and select the values to put in the columns, then row2 etc. This can get pretty cumbersome if you have 50 variables involved though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 16:18:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-2-correlation-tables-into-1-1-above-1-below-the/m-p/835457#M330299</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-27T16:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: Combining 2 correlation tables into 1.  (1 above, 1 below the diagonal)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-2-correlation-tables-into-1-1-above-1-below-the/m-p/835797#M330455</link>
      <description>&lt;P&gt;Speaking of looping over elements in a correlation matrix, I recently wrote about how to convert the correlation matrix to a "long format" that shows the pairwise correlations in a list format:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2022/09/26/correlations-to-list.html" target="_self"&gt;"Display correlations in a list format"&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DATA step loop for that purpose is similar to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s loop here since it processes the same configuration of data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 09:47:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-2-correlation-tables-into-1-1-above-1-below-the/m-p/835797#M330455</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-09-29T09:47:23Z</dc:date>
    </item>
  </channel>
</rss>

