<?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: chi-squared test for every value of a categorical variable with a grouping variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788571#M81388</link>
    <description>&lt;P&gt;Exactly what Chi-squared test do you want? Please be specific and detailed and reference the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data only has 0s and 1s within a cause_death, you can only test to see if the proportion of 0s (or the proportion of 1s) is equal to some specific value which you can choose. This is not really a chi-squared test at all, it is a binomial test or if the sample size is large enough, you can do a z-test approximation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to test the ENTIRE table that you show across all cause_death values, you can of course do that with a chi-squared test, but then you are not testing "every value of a categorical variable", you are doing a global test.&lt;/P&gt;</description>
    <pubDate>Wed, 05 Jan 2022 23:09:37 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-01-05T23:09:37Z</dc:date>
    <item>
      <title>chi-squared test for every value of a categorical variable with a grouping variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788555#M81385</link>
      <description>&lt;DIV&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have a dataset with 60,000 pts with cause of death listed as an ICD 10 code for each patient (variable name: cause_death). The grouping variable is AP ( 0= No/ 1= Yes). So I want to see if there are any significant differences in each of those ICD 10 codes between the two groups. These ICD 10 codes are captured in one variable cause_death and there are about 300 different ICD 10 codes listed within the cause_death variable. I would appreciate if anyone can help me with the SAS code for chi-squared test with p-va;ue comparison for each ICD 10 code within the cause_death variable by grouping variable AP.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much in advance!&lt;BR /&gt;SM&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 05 Jan 2022 21:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788555#M81385</guid>
      <dc:creator>sms1891</dc:creator>
      <dc:date>2022-01-05T21:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: chi-squared test for every value of a categorical variable with a grouping variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788560#M81386</link>
      <description>&lt;P&gt;Please show an example of what your input data looks like and what you want as output. &lt;BR /&gt;I'm not sure if you're looking for a two way or one way chi square? Guessing one way the way the question is formulated. &lt;BR /&gt;Is the ODS results ok?&lt;BR /&gt;&lt;BR /&gt;Rough example of how that could look, I can add more details once you respond with the requested information. &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=class;
by sex age;
run;

ods output onewaychisq=want;
proc freq data=class;
by sex;
table age /chisq;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/146852"&gt;@sms1891&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;DIV&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a dataset with 60,000 pts with cause of death listed as an ICD 10 code for each patient (variable name: cause_death). The grouping variable is AP ( 0= No/ 1= Yes). So I want to see if there are any significant differences in each of those ICD 10 codes between the two groups. These ICD 10 codes are captured in one variable cause_death and there are about 300 different ICD 10 codes listed within the cause_death variable. I would appreciate if anyone can help me with the SAS code for chi-squared test with p-va;ue comparison for each ICD 10 code within the cause_death variable by grouping variable AP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much in advance!&lt;BR /&gt;SM&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 22:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788560#M81386</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-05T22:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: chi-squared test for every value of a categorical variable with a grouping variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788570#M81387</link>
      <description>&lt;P&gt;Hi reeza,&lt;/P&gt;&lt;P&gt;Thank you for the response. Here is what my data looks like (below).Attaching the summary table for the cause_death by AP variable as a &lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Summary Table.jpg" style="width: 481px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67150iDEB0307C50FA1C7B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Summary Table.jpg" alt="Summary Table.jpg" /&gt;&lt;/span&gt;pic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; Cause_death&amp;nbsp; AP&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;I251&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; C349&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; C349&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; J449&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; J449&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; J449&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;8&amp;nbsp; &amp;nbsp;F03&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;9&amp;nbsp; &amp;nbsp; I250&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;10&amp;nbsp; &amp;nbsp; I500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;11&amp;nbsp; &amp;nbsp; I250&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;12&amp;nbsp; &amp;nbsp; &amp;nbsp; I250&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 23:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788570#M81387</guid>
      <dc:creator>sms1891</dc:creator>
      <dc:date>2022-01-05T23:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: chi-squared test for every value of a categorical variable with a grouping variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788571#M81388</link>
      <description>&lt;P&gt;Exactly what Chi-squared test do you want? Please be specific and detailed and reference the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data only has 0s and 1s within a cause_death, you can only test to see if the proportion of 0s (or the proportion of 1s) is equal to some specific value which you can choose. This is not really a chi-squared test at all, it is a binomial test or if the sample size is large enough, you can do a z-test approximation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to test the ENTIRE table that you show across all cause_death values, you can of course do that with a chi-squared test, but then you are not testing "every value of a categorical variable", you are doing a global test.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 23:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788571#M81388</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-05T23:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: chi-squared test for every value of a categorical variable with a grouping variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788572#M81389</link>
      <description>&lt;P&gt;I want to compare the frequencies of each of the ICD 10 codes, for example,&amp;nbsp; I251 8.6% vs 6.67% between AP 0/1, to check if there is a significant difference with a p-value. Similarly, I want to do it for all ICD 10 codes listed, C349, J449, I219, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 23:08:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788572#M81389</guid>
      <dc:creator>sms1891</dc:creator>
      <dc:date>2022-01-05T23:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: chi-squared test for every value of a categorical variable with a grouping variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788573#M81390</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/146852"&gt;@sms1891&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to compare the frequencies of each of the ICD 10 codes, for example,&amp;nbsp; I251 8.6% vs 6.67% between AP 0/1, to check if there is a significant difference with a p-value. Similarly, I want to do it for all ICD 10 codes listed, C349, J449, I219, etc.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Unless I am misunderstanding, this is not a Chi-squared test. You could test to see if the I251 percent of 0s and 1s is equal to a specific value, such as 10% (or any other number you want), but you have to specify the number. It is a binomial test or if the sample size is large, you can approximate it with a z-test.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 23:18:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788573#M81390</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-05T23:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: chi-squared test for every value of a categorical variable with a grouping variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788592#M81391</link>
      <description>&lt;P&gt;1. I can't program off a picture and I'm not typing out your data. Your sample below is too small to work with.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. You didn't show what you wanted as output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you run the example I posted? How close does it get you to what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/146852"&gt;@sms1891&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi reeza,&lt;/P&gt;
&lt;P&gt;Thank you for the response. Here is what my data looks like (below).Attaching the summary table for the cause_death by AP variable as a &lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Summary Table.jpg" style="width: 481px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67150iDEB0307C50FA1C7B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Summary Table.jpg" alt="Summary Table.jpg" /&gt;&lt;/span&gt;pic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; Cause_death&amp;nbsp; AP&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;I251&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; C349&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; C349&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;4&amp;nbsp; &amp;nbsp; J449&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;6&amp;nbsp; &amp;nbsp; J449&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;7&amp;nbsp; &amp;nbsp; J449&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;8&amp;nbsp; &amp;nbsp;F03&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;9&amp;nbsp; &amp;nbsp; I250&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;10&amp;nbsp; &amp;nbsp; I500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;11&amp;nbsp; &amp;nbsp; I250&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;12&amp;nbsp; &amp;nbsp; &amp;nbsp; I250&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 03:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788592#M81391</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-06T03:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: chi-squared test for every value of a categorical variable with a grouping variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788594#M81392</link>
      <description>&lt;P&gt;A one way chi square test is equivalent to the binomial test with the proportion being equal to 0.5/50% in this case?&lt;/P&gt;
&lt;P&gt;My stats are getting rustier by the day but I do think it's somewhat valid, though possibly not ideal.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would definitely need to correct for multiple testing though.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/146852"&gt;@sms1891&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to compare the frequencies of each of the ICD 10 codes, for example,&amp;nbsp; I251 8.6% vs 6.67% between AP 0/1, to check if there is a significant difference with a p-value. Similarly, I want to do it for all ICD 10 codes listed, C349, J449, I219, etc.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Unless I am misunderstanding, this is not a Chi-squared test. You could test to see if the I251 percent of 0s and 1s is equal to a specific value, such as 10% (or any other number you want), but you have to specify the number. It is a binomial test or if the sample size is large, you can approximate it with a z-test.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&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>Thu, 06 Jan 2022 04:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788594#M81392</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-06T04:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: chi-squared test for every value of a categorical variable with a grouping variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788596#M81393</link>
      <description>&lt;P&gt;PaigeMiller,&lt;/P&gt;&lt;P&gt;I have a total of 55489 patients who died.&amp;nbsp; All these patients died of some cause (cause_death) which is captured as an ICD 10 code. My exposure variable is AP (Yes= 1, No = 0). Out of 55489, 15763 had AP (AP=1), 39726 did not have AP (AP =0). I want to compare each and every ICD 10 code % with the grouping variable AP.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If 8.6% of No-AP (3416/39726) died of I251 and 6.67% of AP (1051/15763) died of I251, then there are remaining 91.4% of No-AP (n=36310) and 93.33% of AP patients (n=14712) who died of other reason other than I251. So this would technically become a 2x2 table and I want to do a chi-squared test to compare if 8.6% is statistically significant compared to the 6.67%.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Similarly, for patients who died of C349, there would be a unique 2x2 table based off the grouping variable. 2809 of 39726 No-AP (7.07%) died of C349 and 978 of 15763 AP (6.20%) died of C349.&amp;nbsp;So this would again become a 2x2 table and I want to do a chi-squared test to compare if 7.07% is statistically significant compared to 6.20%.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have more than 300 causes of death for all patients who died (n=55489). I do not want to manually do a chi-squared test for each and every cause of death for comparison. I would love to get some help, if there is a better way to handle this using SAS coding. I hope you understood my question now. Please do let me know if you need any further clarification. I have posted my data structure example in my reply to Reeza post along with a picture of the summary table by AP status. I am also attaching the 2x2 table that I explained for each code above as a picture. Obviously this is a manual way of doing a chi-squared test by feeding the 2x2 table in a data step and running the chi-squared test in a proc freq step.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2x2 Table for each cause of death.jpg" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67152i52E15D8BBB125EFB/image-size/large?v=v2&amp;amp;px=999" role="button" title="2x2 Table for each cause of death.jpg" alt="2x2 Table for each cause of death.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 04:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788596#M81393</guid>
      <dc:creator>sms1891</dc:creator>
      <dc:date>2022-01-06T04:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: chi-squared test for every value of a categorical variable with a grouping variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788599#M81394</link>
      <description>&lt;P&gt;I found this post from another post, similar to what I am looking for, but it is not working for my data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Chi-square-independence-test-for-each-item-of-the/m-p/771695#M244937" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Chi-square-independence-test-for-each-item-of-the/m-p/771695#M244937&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=""&gt;&lt;CODE&gt;%let dsn=sashelp.cars;
%let var1=origin;
%let var2=type;

data want(keep=_byval1 _byval2 &amp;amp;var1 &amp;amp;var2 _count) / view=want;
if _n_=1 then do;
  dcl hash h();
  h.definekey("&amp;amp;var1", "&amp;amp;var2");
  h.definedata("&amp;amp;var1", "&amp;amp;var2", '_count');
  h.definedone();
  dcl hiter hi('h');

  dcl hash k(dataset:"&amp;amp;dsn", ordered:'a');
  k.definekey("&amp;amp;var1");
  k.definedone();
  dcl hiter hi1('k');
  dcl hiter hi2('k');
end;
set &amp;amp;dsn end=last;
if h.find()=0 then _count+1;
else _count=1;
h.replace();
if last;
do while(hi1.next()=0);
  _byval1=&amp;amp;var1;
  hi2.setcur();
  do while(hi2.next()=0);
    _byval2=&amp;amp;var1;
    do while(hi.next()=0);
      if &amp;amp;var1=_byval1 | &amp;amp;var1=_byval2 then output;
    end;
  end;
end;
run;

proc freq data=want;
by _byval1 _byval2;
weight _count;
tables &amp;amp;var1*&amp;amp;var2 / chisq /* missing */;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 04:29:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788599#M81394</guid>
      <dc:creator>sms1891</dc:creator>
      <dc:date>2022-01-06T04:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: chi-squared test for every value of a categorical variable with a grouping variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788633#M81395</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/146852"&gt;@sms1891&lt;/a&gt;&amp;nbsp;Thanks, that is much clearer now what you want. I don't have the time to work on this right now, maybe later. But you still need to provide a portion of your data as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;). Other formats are not acceptable.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 11:49:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/chi-squared-test-for-every-value-of-a-categorical-variable-with/m-p/788633#M81395</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-06T11:49:48Z</dc:date>
    </item>
  </channel>
</rss>

