<?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 3 way cross tabulation (chi square test) in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620416#M29884</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I am trying to write code in SAS University edition to do a 3-way cross tabulation. For example, if I have 3 categorical variables and I want to look at presisting condition status(preex_status) and insurance coverage(coverage_status) by year whether before or after the policy went into effect (year_class). Each variable has two categories the year_Class has 'pre' and 'post' and the other two have 0 and 1 for yes or no response. I wrote following code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data = mydata;&lt;/P&gt;&lt;P&gt;tables preex_status*coverage_status*year_Class / chisq;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However it gives a 2*2 table controlling for preex_status. I cannot use the 'By' statement gives me an error saying "data is not sorted in ascending sequence. I was expecting a table as below:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Pre&lt;/TD&gt;&lt;TD&gt;Post&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Coverage status&lt;/TD&gt;&lt;TD&gt;Pre-existing condition&lt;/TD&gt;&lt;TD&gt;No&lt;/TD&gt;&lt;TD&gt;Pre-existing condition&lt;/TD&gt;&lt;TD&gt;No&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Yes&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&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;No&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&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;Is this possible or am I using the wrong statistical test? Can someone help me solve it? Thank yo&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jan 2020 03:13:22 GMT</pubDate>
    <dc:creator>drteju</dc:creator>
    <dc:date>2020-01-28T03:13:22Z</dc:date>
    <item>
      <title>3 way cross tabulation (chi square test)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620416#M29884</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I am trying to write code in SAS University edition to do a 3-way cross tabulation. For example, if I have 3 categorical variables and I want to look at presisting condition status(preex_status) and insurance coverage(coverage_status) by year whether before or after the policy went into effect (year_class). Each variable has two categories the year_Class has 'pre' and 'post' and the other two have 0 and 1 for yes or no response. I wrote following code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data = mydata;&lt;/P&gt;&lt;P&gt;tables preex_status*coverage_status*year_Class / chisq;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However it gives a 2*2 table controlling for preex_status. I cannot use the 'By' statement gives me an error saying "data is not sorted in ascending sequence. I was expecting a table as below:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Pre&lt;/TD&gt;&lt;TD&gt;Post&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Coverage status&lt;/TD&gt;&lt;TD&gt;Pre-existing condition&lt;/TD&gt;&lt;TD&gt;No&lt;/TD&gt;&lt;TD&gt;Pre-existing condition&lt;/TD&gt;&lt;TD&gt;No&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Yes&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&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;No&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&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;Is this possible or am I using the wrong statistical test? Can someone help me solve it? Thank yo&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 03:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620416#M29884</guid>
      <dc:creator>drteju</dc:creator>
      <dc:date>2020-01-28T03:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: 3 way cross tabulation (chi square test)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620417#M29885</link>
      <description>&lt;P&gt;Looks like a similar question was asked here:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulations-chi-square-tests/td-p/38769" target="_blank"&gt;https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulations-chi-square-tests/td-p/38769&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 03:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620417#M29885</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-01-28T03:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: 3 way cross tabulation (chi square test)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620418#M29886</link>
      <description>&lt;P&gt;Hi, thank you for the reply. I have tried that solution but does not work in my case. It gives me an error message that, "data is not sorted in ascending sequence'. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 03:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620418#M29886</guid>
      <dc:creator>drteju</dc:creator>
      <dc:date>2020-01-28T03:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: 3 way cross tabulation (chi square test)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620419#M29887</link>
      <description>&lt;P&gt;Try running this prior to proc freq:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=mydata;
by preex_status coverage_status year_Class;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jan 2020 03:30:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620419#M29887</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-01-28T03:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: 3 way cross tabulation (chi square test)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620420#M29888</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270457"&gt;@unison&lt;/a&gt;&amp;nbsp;that definitely helped and I could run the code. But i still got 2 tables. Is there anyway i could get one table like below:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Before&lt;/TD&gt;&lt;TD&gt;Policy&lt;/TD&gt;&lt;TD&gt;after&lt;/TD&gt;&lt;TD&gt;policy&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Coverage status&lt;/TD&gt;&lt;TD&gt;Pre-existing condition&lt;/TD&gt;&lt;TD&gt;No&lt;/TD&gt;&lt;TD&gt;Pre-existing condition&lt;/TD&gt;&lt;TD&gt;No&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Yes&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&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;No&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&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;Thank you again &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 03:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620420#M29888</guid>
      <dc:creator>drteju</dc:creator>
      <dc:date>2020-01-28T03:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: 3 way cross tabulation (chi square test)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620421#M29889</link>
      <description>&lt;P&gt;What do you want to go in the blank spots?&lt;/P&gt;
&lt;P&gt;if it’s just the frequencies then you can use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;out=outfreq&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;On the table statement (next to your chisq option). Then you would do something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=outfreq;
column sex height, count weight,count;
define sex/group;
define height/across;
define weight/across;
define count/analysis sum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jan 2020 03:59:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620421#M29889</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-01-28T03:59:03Z</dc:date>
    </item>
    <item>
      <title>Re: 3 way cross tabulation (chi square test)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620427#M29890</link>
      <description>&lt;P&gt;Thanks but that won't work. But i think i might have solved it. I just created a new variable using condition statement and created four categories for the new variable where 1. a person has condition and insurance. 2. Has condition but no insurance 3. No condition but has insurance 4. no condition and no insurance then used this new variable for a two way table with year variable using code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc freq data=mythesis.jdata ;&lt;BR /&gt;&lt;BR /&gt;  tables condition_coverage*year_class/ chisq;&lt;BR /&gt;  weight perweight1;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;and got following output:&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Table&amp;nbsp;of&amp;nbsp;condition_coverage&amp;nbsp;by&amp;nbsp;year_class&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;condition_coverage&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;year_class&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Frequency&lt;BR /&gt;Percent&lt;BR /&gt;Row&amp;nbsp;Pct&lt;BR /&gt;Col&amp;nbsp;Pct&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;post&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;pre&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Total&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;nocond_hascovera&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3.364E7&lt;BR /&gt;21.26&lt;BR /&gt;51.85&lt;BR /&gt;42.74&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3.124E7&lt;BR /&gt;19.74&lt;BR /&gt;48.15&lt;BR /&gt;39.28&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;6.488E7&lt;BR /&gt;41.01&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;nocond_nocoverag&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;5818615&lt;BR /&gt;3.68&lt;BR /&gt;37.69&lt;BR /&gt;7.39&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;9618986&lt;BR /&gt;6.08&lt;BR /&gt;62.31&lt;BR /&gt;12.10&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1.544E7&lt;BR /&gt;9.76&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;preex_nocoverage&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3492139&lt;BR /&gt;2.21&lt;BR /&gt;36.03&lt;BR /&gt;4.44&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;6198915&lt;BR /&gt;3.92&lt;BR /&gt;63.97&lt;BR /&gt;7.80&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;9691053&lt;BR /&gt;6.13&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;prex_hascoverage&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3.575E7&lt;BR /&gt;22.60&lt;BR /&gt;52.41&lt;BR /&gt;45.43&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3.246E7&lt;BR /&gt;20.52&lt;BR /&gt;47.59&lt;BR /&gt;40.82&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;6.821E7&lt;BR /&gt;43.11&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Total&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;7.87E7&lt;BR /&gt;49.74&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;7.951E7&lt;BR /&gt;50.26&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1.582E8&lt;BR /&gt;100.00&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="proc_title_group"&gt;&lt;P class="c proctitle"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looks like that solves the question. Will update once i get it verified if this solution is correct. Thanks again.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 04:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulation-chi-square-test/m-p/620427#M29890</guid>
      <dc:creator>drteju</dc:creator>
      <dc:date>2020-01-28T04:27:29Z</dc:date>
    </item>
  </channel>
</rss>

