<?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: correlation matrix of binary variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767204#M243202</link>
    <description>Paige,&lt;BR /&gt;That is chisquare test . &lt;BR /&gt;And Phi Coefficient  / Contingency Coefficient   measure the association between two variables NOT correlation .</description>
    <pubDate>Sat, 11 Sep 2021 12:21:58 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2021-09-11T12:21:58Z</dc:date>
    <item>
      <title>correlation matrix of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767185#M243188</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like to ask please&amp;nbsp; a question.&lt;/P&gt;
&lt;P&gt;In my source data set there are 10 binary variables (each varaible get value 1 or 0 ).&lt;/P&gt;
&lt;P&gt;Each variable has a meaning of another overide businss rule.&lt;/P&gt;
&lt;P&gt;I want to create a matrix report(10x10) with information of the correlation (assosiation) between the binary variables.&lt;/P&gt;
&lt;P&gt;The target is to see which variables (Overide rules) are working together and which are not working together.&lt;/P&gt;
&lt;P&gt;May anyone send an example how to do it .&lt;/P&gt;
&lt;P&gt;Let's say that the user define the varaibles list in a macro varaiable.&lt;/P&gt;
&lt;P&gt;%let List= Z1+Z2+Z3+Z4+Z5+Z6+Z7+Z8+Z9+Z10;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Sep 2021 07:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767185#M243188</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-09-11T07:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: correlation matrix of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767190#M243192</link>
      <description>&lt;P&gt;See here whether this is what you want: &lt;A href="https://data-flair.training/blogs/sas-correlation-analysis/" target="_blank"&gt;https://data-flair.training/blogs/sas-correlation-analysis/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Sep 2021 10:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767190#M243192</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-09-11T10:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: correlation matrix of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767199#M243198</link>
      <description>&lt;P&gt;Check COSINE correlation.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp; wrote blog about it .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2019/09/05/cosine-similarity-recommendations.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2019/09/05/cosine-similarity-recommendations.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2019/09/03/cosine-similarity.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2019/09/03/cosine-similarity.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Sep 2021 11:26:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767199#M243198</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-11T11:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: correlation matrix of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767203#M243201</link>
      <description>&lt;P&gt;You probably want the &lt;A href="https://en.wikipedia.org/wiki/Phi_coefficient" target="_self"&gt;Phi coefficient&lt;/A&gt;, which is the equivalent of the Pearson correlation for binary variables. This &lt;A href="https://stats.idre.ucla.edu/sas/output/proc-freq/" target="_self"&gt;can be computed in PROC FREQ&lt;/A&gt; for any pair of variables, and so if you really want a 10x10 table, you'd have to write a macro and loop over all possible pairs of variables.&lt;/P&gt;</description>
      <pubDate>Sat, 11 Sep 2021 12:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767203#M243201</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-11T12:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: correlation matrix of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767204#M243202</link>
      <description>Paige,&lt;BR /&gt;That is chisquare test . &lt;BR /&gt;And Phi Coefficient  / Contingency Coefficient   measure the association between two variables NOT correlation .</description>
      <pubDate>Sat, 11 Sep 2021 12:21:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767204#M243202</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-11T12:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: correlation matrix of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767214#M243205</link>
      <description>&lt;P&gt;In the case of two binary variables, I am not aware of any difference between "association" and "correlation".&lt;/P&gt;</description>
      <pubDate>Sat, 11 Sep 2021 16:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767214#M243205</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-11T16:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: correlation matrix of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767216#M243206</link>
      <description>&lt;P&gt;Show some example data.&lt;/P&gt;
&lt;P&gt;Or we could use the example data in Rick Wiklen's blog.&amp;nbsp;&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2019/09/05/cosine-similarity-recommendations.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2019/09/05/cosine-similarity-recommendations.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data recipes;
   input Recipe $ 1-20
      (Tomato Garlic Salt Onion TomatoPaste OliveOil Celery Broth 
       GreenPepper Cumin Flour BrownSugar BayLeaf GroundBeef 
       BlackPepper ChiliPowder Cilantro Carrot CayennePepper Oregano 
       Oil Parsley PorkSausage RedPepper Paprika Thyme Tomatillo 
       JalapenoPepper WorcestershireSauce Lime
       Eggplant GreenOlives Capers Sugar) (1.);
datalines;
Spag Sauce          1111110000000000000101000000000000
Spag Meat Sauce     1111111010001100010000110000000000
Eggplant Relish     0111110000000000000000000000001111
Creole Sauce        1011111110000010000000001100100000
Salsa               1111000000000000100000000011010000
Enchilada Sauce     1000000101110001001010000000000000
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To compare the COLUMNS instead of the ROWS just transpose the data first.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=recipes out=ingrediants name=ingrediant ;
  id recipe ;
  var _numeric_;
run;
proc distance data=ingrediants out=cos_ingrediants method=COSINE shape=square;
   var ratio(_NUMERIC_);
   id ingrediant;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So in your case if you make your macro variable contain a space delimited list of variable names (instead of + delimited).&amp;nbsp; You might even be able to use a variable list syntax.&lt;/P&gt;
&lt;P&gt;Then the code is something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let List= Z1-Z10;
proc transpose data=HAVE out=columns name=COLUMN;
  var &amp;amp;list;
run;
proc distance data=columns out=cos method=COSINE shape=square;
   var ratio(_NUMERIC_);
   id COLUMN;
run;
proc print data=cos;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So if I use RECIPES as the HAVE and set LIST=&amp;nbsp;Tomato Garlic Salt Onion then the result is:&lt;/P&gt;
&lt;PRE&gt;Obs    COLUMN     Tomato     Garlic      Salt      Onion

 1     Tomato    1.00000    0.67082    0.80000    0.80000
 2     Garlic    0.67082    1.00000    0.89443    0.89443
 3     Salt      0.80000    0.89443    1.00000    1.00000
 4     Onion     0.80000    0.89443    1.00000    1.00000


&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Sep 2021 16:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/correlation-matrix-of-binary-variables/m-p/767216#M243206</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-11T16:49:43Z</dc:date>
    </item>
  </channel>
</rss>

