<?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: Find relationship between character variables using chi square (output n*n) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598437#M172576</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293144"&gt;@Bond007&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;freq&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;sashelp&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;heart&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; BP_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Chol_Status &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; BP_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Smoking_Status &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; BP_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Weight_Status&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; Chol_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Smoking_Status &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; Chol_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Weight_Status&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; Smoking_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Weight_Status&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there any way in SAS where the tables statement could be called for entire dataset to do the set of table commands mentioned above internally with all variable combinations?&amp;nbsp; For example: If the dataset has 50-100 character variables, it is difficult to write so many table statements for each combination.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Entire dataset&amp;nbsp;might be a tad excessive.&lt;/P&gt;
&lt;P&gt;You could use something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tables _character_ * _character_ /options.&lt;/P&gt;
&lt;P&gt;Caution: Run that on a small data set with a just a few variables. 50 variables would mean 50*50 = 2500 tables with at least 50 pretty meaningless for the variables when compared with them selves Plus almost half will duplicate results: var1*var2 will have the same chisq as var2*var1. Note that to use the ODS select you have to have the output go to a destination and 2500 tables may fill up the results window. YMMV.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you could use&amp;nbsp;a tables statement like&lt;/P&gt;
&lt;P&gt;tables ( &amp;lt;list of variable names here&amp;gt;) *( &amp;lt;list of other variables here&amp;gt;) / options.&lt;/P&gt;
&lt;P&gt;to compare everyone of the first list with everyone of the second list.&lt;/P&gt;
&lt;P&gt;You can use the lists like A -- D (that is two dashes) to indicate variables that are in sequential columns in the data set or BP: (a colon immediately after the starting characters of a variable name) to use all the variable names that start with the letters BP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest looking at which variables actually make sense to test in a chisq (Hint: addresses, identification variables, phone numbers and such are almost certainly not worth pursuing. Geographic groups like city, zipcode, state might). Break them into two lists and if there are a few specific comparisons that would not get done with the two lists then add them:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tables (&amp;lt;list1&amp;gt;)*(&amp;lt;list2&amp;gt;)&amp;nbsp;&amp;nbsp; var1*var2 var1*var7 /&amp;lt;options&amp;gt;;&lt;/P&gt;
&lt;P&gt;for instance.&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>Tue, 22 Oct 2019 15:45:08 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-10-22T15:45:08Z</dc:date>
    <item>
      <title>Find relationship between character variables using chi square (output n*n)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598109#M172429</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have found the correlation between numeric variables in a dataset. Here is the code I used to do the same. (output n*n matrix format)&lt;/P&gt;&lt;PRE&gt;proc template;
      edit Base.Corr.StackedMatrix;
         column (RowName RowLabel) (Matrix) * (Matrix2);
         edit matrix;
            cellstyle _val_  = -1.00 as {backgroundcolor=CXEEEEEE},
                      _val_ &amp;lt;= -0.75 as {backgroundcolor=red},
                      _val_ &amp;lt;= -0.50 as {backgroundcolor=blue},
                      _val_ &amp;lt;= -0.25 as {backgroundcolor=cyan},
                      _val_ &amp;lt;=  0.25 as {backgroundcolor=white},
                      _val_ &amp;lt;=  0.50 as {backgroundcolor=cyan},
                      _val_ &amp;lt;=  0.75 as {backgroundcolor=blue},
                      _val_ &amp;lt;   1.00 as {backgroundcolor=red},
                      _val_  =  1.00 as {backgroundcolor=CXEEEEEE};
            end;
         end;
      run;
   
   ods html body='corr.html' style=statistical;
   ods listing close;
   proc corr data=cars noprob;
      ods select PearsonCorr;
   run;
   ods listing;
   ods html close;
   
   proc template;
   delete Base.Corr.StackedMatrix;&lt;BR /&gt;   run;&lt;BR /&gt;&lt;BR /&gt;Output:
   &lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xyz.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33324i8DA850124641045C/image-size/large?v=v2&amp;amp;px=999" role="button" title="xyz.PNG" alt="xyz.PNG" /&gt;&lt;/span&gt;&lt;/PRE&gt;&lt;P&gt;I want to compare the character variables using chi square and get a score, similar to the correlation process done for numeric variables. (Required output format n*n: Same as above)&lt;/P&gt;&lt;P&gt;Do I have to edit the proc freq template to get the output I want? How do I achieve the n*n output?&lt;/P&gt;&lt;P&gt;Please help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Bond&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 12:53:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598109#M172429</guid>
      <dc:creator>Bond007</dc:creator>
      <dc:date>2019-10-21T12:53:02Z</dc:date>
    </item>
    <item>
      <title>Re: Find relationship between character variables using chi square (output n*n)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598128#M172439</link>
      <description>&lt;P&gt;Recently&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp; has written a blog about building a recommendation system . which used COSINE to test the correlation of two statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think it is very suited for your question .&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 13:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598128#M172439</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-10-21T13:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Find relationship between character variables using chi square (output n*n)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598137#M172445</link>
      <description>&lt;P&gt;I have to use chi square to calculate the relationship between the character variables in a dataset, considering the correlation can be used for numeric variables only.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 13:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598137#M172445</guid>
      <dc:creator>Bond007</dc:creator>
      <dc:date>2019-10-21T13:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: Find relationship between character variables using chi square (output n*n)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598138#M172446</link>
      <description>&lt;P&gt;I am not aware of a correlation-type measurement for character variables. You might be thinking about testing for the assoication between levels of two categorical variables by using PROC FREQ. For example, if you want to know whether there is an association between weights of patients (measured as (Underweight, Normal, or Overweight) and cholesterol levels (measured as Desirable, Borderline, or High), you can run the following PROC FREQ step and use the CHISQ option to test for association.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=sashelp.heart;
   tables Chol_status*Weight_status / nocol norow chisq;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use multiple TABLES statements if you want to test several pairs of character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, &lt;A href="http://graphs.%20For example, PROC FREQ can create a mosaic plot and a clustered bar chart to visualize frequencies and relative frequencies in a two-way table. Next time you use PROC FREQ, add the PLOTS=ALL option to the TABLES statement and see what you get!  One of my favorite plots for two-way categorical data is the stacked bar chart. " target="_self"&gt;PROC FREQ can also create graphs of your two-way tables.&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 14:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598138#M172446</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-10-21T14:04:34Z</dc:date>
    </item>
    <item>
      <title>Re: Find relationship between character variables using chi square (output n*n)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598173#M172467</link>
      <description>&lt;P&gt;Using the code you mentioned, I will get a similar output of two tables.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="abc.PNG" style="width: 443px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33329iF3BD46E782BE1D75/image-size/large?v=v2&amp;amp;px=999" role="button" title="abc.PNG" alt="abc.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;All I need is the Chi-Square value when two variables are compared and not other details.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If possible, I would prefer the output to be in a format of n*n matrix when the chi-square code is subjected to all the character variables. The output format should be similar to the one that I have mentioned in the question (which I got for correlation of numeric values).&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 16:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598173#M172467</guid>
      <dc:creator>Bond007</dc:creator>
      <dc:date>2019-10-21T16:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: Find relationship between character variables using chi square (output n*n)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598188#M172475</link>
      <description>&lt;P&gt;Assuming that n is the number of variables, there are only n*(n-1)/2 elements, since the matrix you ask for is symmetric and the diagonal elements are uninteresting. Here's how to get the numbers you want. If you really want the info displayed as an n*n matrix, you restructure the statistics into a matrix yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The basic idea is to enumerate the pairwise combinations, &lt;A href="https://blogs.sas.com/content/iml/2017/01/09/ods-output-any-statistic.html" target="_self"&gt;use ODS OUTPUT to save the statistics to a SAS data set&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;and then display the statistics in the form you want. Here is the way you could create the chi-square statistics for the 6 pairwise tests for the four variables BP_Status, Chol_Status, Smoking_Status, and Weight_Status in the Sashelp.Heart data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods exclude all;
ods output ChiSq(persist)=chisq(where=(statistic="Chi-Square")
           rename=(Value=ChiSq));

proc freq data=sashelp.heart;
   tables BP_Status * Chol_Status / nocol norow chisq;
   tables BP_Status * Smoking_Status / nocol norow chisq;
   tables BP_Status * Weight_Status/ nocol norow chisq;
   tables Chol_Status * Smoking_Status / nocol norow chisq;
   tables Chol_Status * Weight_Status/ nocol norow chisq;
   tables Smoking_Status * Weight_Status/ nocol norow chisq;
run;

ods exclude none;

proc print data=ChiSq;
   var Table Statistic DF ChiSq Prob;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To visualize the data, you might consider a bar chart of the pairwise associations. &lt;A href="https://blogs.sas.com/content/iml/2017/08/16/pairwise-correlations-bar-chart.html" target="_self"&gt;You can make a similar bar chart for correlations.&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 17:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598188#M172475</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-10-21T17:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Find relationship between character variables using chi square (output n*n)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598192#M172478</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293144"&gt;@Bond007&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Using the code you mentioned, I will get a similar output of two tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All I need is the Chi-Square value when two variables are compared and not other details.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If possible, I would prefer the output to be in a format of n*n matrix when the chi-square code is subjected to all the character variables. The output format should be similar to the one that I have mentioned in the question (which I got for correlation of numeric values).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;One way to get an output data set of just the basic chi-square statistics:&lt;/P&gt;
&lt;PRE&gt;ods select chisq;
proc freq data=sashelp.heart ;
   ods output chisq=work.chisq;
   tables (Chol_status smoking_status)*Weight_status / nocol norow chisq;
run;&lt;/PRE&gt;
&lt;P&gt;You would have to parse the data set a bit to select the statistic(s) you want and separate the variable names from the TABLE variable.&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data work.report;
   set work.chisq;
   where statistic='Chi-Square';
   length var1 var2 $ 32;
   var1 = scan(table,2,' * ');
   var2 = scan(table,3,' * ');
run;

proc report data=work.report;
   column var2 var1,prob;
   define var2 /group;
   define var1/across;
   define prob/ ' '  ;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that chi-square statistic values without additional information tend to be a tad difficult to interpret. So I use the p-value above in the example.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 17:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598192#M172478</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-21T17:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: Find relationship between character variables using chi square (output n*n)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598347#M172553</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;freq&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;sashelp&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;heart&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; BP_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Chol_Status &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; BP_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Smoking_Status &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; BP_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Weight_Status&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; Chol_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Smoking_Status &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; Chol_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Weight_Status&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; Smoking_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Weight_Status&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there any way in SAS where the tables statement could be called for entire dataset to do the set of table commands mentioned above internally with all variable combinations?&amp;nbsp; For example: If the dataset has 50-100 character variables, it is difficult to write so many table statements for each combination.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 08:57:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598347#M172553</guid>
      <dc:creator>Bond007</dc:creator>
      <dc:date>2019-10-22T08:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Find relationship between character variables using chi square (output n*n)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598362#M172555</link>
      <description>&lt;P&gt;&amp;gt; i&lt;SPAN&gt;s there any way in SAS where the tables statement could be called for entire dataset to do the set of table &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;gt; commands mentioned above internally with all variable combinations?&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;No, not automatically. You would have to generate those statements yourself by using either MACRO or by using CALL EXECUTE to generate the code in the DATA step.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The reason this is not "automatic" is that I've never seen anyone want to perform this kind of analysis. It is not clear to me that it is a useful computation. Chi-square tests for association are quite different from correlations. For large data, almost all the tests will reject the hypothesis of association. You will also encounter computational issues when you encounter a character variable such as Name, ID, address, ... that has many levels. PROC FREQ will not perform well when you ask for a frequency table of Name*Address. because the&amp;nbsp; table will be huge and will require a LOT of memory,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can google for how to generate all pairwise combinations of variables in SAS, but I encourage you to rethink what you are trying to accomplish and whether your efforts are likely to give you any meaningful insights into your data.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 10:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598362#M172555</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-10-22T10:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Find relationship between character variables using chi square (output n*n)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598363#M172556</link>
      <description>&lt;P&gt;Thanks for the help. Much appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 10:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598363#M172556</guid>
      <dc:creator>Bond007</dc:creator>
      <dc:date>2019-10-22T10:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Find relationship between character variables using chi square (output n*n)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598437#M172576</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293144"&gt;@Bond007&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;freq&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;sashelp&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;heart&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; BP_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Chol_Status &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; BP_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Smoking_Status &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; BP_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Weight_Status&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; Chol_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Smoking_Status &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; Chol_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Weight_Status&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; Smoking_Status &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; Weight_Status&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; nocol norow chisq&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there any way in SAS where the tables statement could be called for entire dataset to do the set of table commands mentioned above internally with all variable combinations?&amp;nbsp; For example: If the dataset has 50-100 character variables, it is difficult to write so many table statements for each combination.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Entire dataset&amp;nbsp;might be a tad excessive.&lt;/P&gt;
&lt;P&gt;You could use something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tables _character_ * _character_ /options.&lt;/P&gt;
&lt;P&gt;Caution: Run that on a small data set with a just a few variables. 50 variables would mean 50*50 = 2500 tables with at least 50 pretty meaningless for the variables when compared with them selves Plus almost half will duplicate results: var1*var2 will have the same chisq as var2*var1. Note that to use the ODS select you have to have the output go to a destination and 2500 tables may fill up the results window. YMMV.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you could use&amp;nbsp;a tables statement like&lt;/P&gt;
&lt;P&gt;tables ( &amp;lt;list of variable names here&amp;gt;) *( &amp;lt;list of other variables here&amp;gt;) / options.&lt;/P&gt;
&lt;P&gt;to compare everyone of the first list with everyone of the second list.&lt;/P&gt;
&lt;P&gt;You can use the lists like A -- D (that is two dashes) to indicate variables that are in sequential columns in the data set or BP: (a colon immediately after the starting characters of a variable name) to use all the variable names that start with the letters BP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest looking at which variables actually make sense to test in a chisq (Hint: addresses, identification variables, phone numbers and such are almost certainly not worth pursuing. Geographic groups like city, zipcode, state might). Break them into two lists and if there are a few specific comparisons that would not get done with the two lists then add them:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tables (&amp;lt;list1&amp;gt;)*(&amp;lt;list2&amp;gt;)&amp;nbsp;&amp;nbsp; var1*var2 var1*var7 /&amp;lt;options&amp;gt;;&lt;/P&gt;
&lt;P&gt;for instance.&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>Tue, 22 Oct 2019 15:45:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-relationship-between-character-variables-using-chi-square/m-p/598437#M172576</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-22T15:45:08Z</dc:date>
    </item>
  </channel>
</rss>

