<?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: McNemar Test with a Zero Cell in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/McNemar-Test-with-a-Zero-Cell/m-p/525393#M73514</link>
    <description>&lt;P&gt;Thank you both&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52346"&gt;@lopezr&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;. Both of your solutions presuppose that the cell counts are known, and I didn't specify that I was looking for a solution where these counts are not known. A colleague of mine suggested the following solution and it worked, so I am including it here. Var1 and var2 are grouping variables and var3 and var4 are the variables in the 2x2 table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc means data=xxxxxx completetypes noprint nway;&lt;BR /&gt;class var1 var2&amp;nbsp;var3&amp;nbsp;var4;&lt;BR /&gt;output out=freqnew(rename=(_freq_=count) drop=_type_);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=freqnew;&lt;BR /&gt;by&amp;nbsp;var1&amp;nbsp;var2&amp;nbsp;var3&amp;nbsp;var4 _stat_ count;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data analysis (keep=var1&amp;nbsp;var2&amp;nbsp;var3&amp;nbsp;var4 count);&lt;BR /&gt;set freqnew; by var1&amp;nbsp;var2&amp;nbsp;var3&amp;nbsp;var4 _stat_ count;&lt;BR /&gt;if first.var4;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc print data=analysis noobs;&lt;BR /&gt;title1 "Zero Table Cell Added to Raw Data";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc Freq data=analysis;&lt;BR /&gt;by&amp;nbsp;var1&amp;nbsp;var2;&lt;BR /&gt;Tables var3*var4 / missing agree;&lt;BR /&gt;exact mcnem;&lt;BR /&gt;weight count / zeros;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Jan 2019 13:20:24 GMT</pubDate>
    <dc:creator>mrprerost</dc:creator>
    <dc:date>2019-01-08T13:20:24Z</dc:date>
    <item>
      <title>McNemar Test with a Zero Cell</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/McNemar-Test-with-a-Zero-Cell/m-p/524564#M73502</link>
      <description>&lt;P&gt;A previous user asked a question about how to run a McNemar's test with cells that have 0 frequencies, and a solution was proposed:&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; view success &lt;SPAN class="token function"&gt;count&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;1 1 30
1 0 0
2 1 26
2 0 4&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&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;have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
	&lt;SPAN class="token statement"&gt;weight&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;count&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token keyword"&gt;tables&lt;/SPAN&gt; view&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;success &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; agree&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token number"&gt;ex&lt;/SPAN&gt;act mcnem&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;This works when you have the summary data, but can the same result be achieved when you are using an actual dataset (not inputting the 2x2 cell counts) and not using a 'weight' statement? I'm using SAS 9.4.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 14:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/McNemar-Test-with-a-Zero-Cell/m-p/524564#M73502</guid>
      <dc:creator>mrprerost</dc:creator>
      <dc:date>2019-01-04T14:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: McNemar Test with a Zero Cell</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/McNemar-Test-with-a-Zero-Cell/m-p/524609#M73504</link>
      <description>&lt;P&gt;You can achieve this with the actual data set by assigning weight = 1 to observations in your data and adding a single observation representing the 0 frequency cell with a weight of 0.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have (drop = i);
    /* generate actual data set */
    do i = 1 to 30;
        view = 1;
        success = 1;
        weight = 1;
    output;
    end;
    do i = 1 to 26;
        view = 2;
        success = 1;
        weight = 1;
    output;
    end;
    do i = 1 to 4;
        view = 2;
        success = 0;
        weight = 1;
    output;
    end;
    /* 0 freq cell with weight 0 */
    do i = 1 to 1;
        view = 1;
        success = 0;
        weight = 0;
    output;
    end;
run;

proc freq data=have; 
    weight weight;
    tables view*success / agree;
    exact mcnem;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Jan 2019 16:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/McNemar-Test-with-a-Zero-Cell/m-p/524609#M73504</guid>
      <dc:creator>lopezr</dc:creator>
      <dc:date>2019-01-04T16:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: McNemar Test with a Zero Cell</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/McNemar-Test-with-a-Zero-Cell/m-p/524641#M73507</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/253449"&gt;@mrprerost&lt;/a&gt;&amp;nbsp;and&amp;nbsp;welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a &lt;EM&gt;single&lt;/EM&gt; zero cell in the 2x2 table it is not necessary to create an extra observation with weight 0 because its weight would be 0 anyway. So, in&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52346"&gt;@lopezr&lt;/a&gt;'s&amp;nbsp;code you can omit the last DO loop without changing the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note, however, that the &lt;A href="https://communities.sas.com/t5/Statistical-Procedures/McNemar-Test-with-a-Zero-Cell/m-p/427929#M22483" target="_blank"&gt;&lt;EM&gt;correct&lt;/EM&gt; solution in the other thread&lt;/A&gt; involved &lt;EM&gt;two&lt;/EM&gt; zero cells &lt;EM&gt;in the same row&lt;/EM&gt;. (Unfortunately, the accepted solution there did not produce the correct result, but the original poster,&amp;nbsp;&lt;SPAN class=""&gt;&lt;A id="link_33" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/185289" target="_self"&gt;Ahmed_Hegazy&lt;/A&gt;, then provided a correct solution.) In this case you do need&amp;nbsp;a zero-weight&amp;nbsp;observation in the dataset. As above, it is sufficient to create a single observation (the second zero-weight cell then arises automatically). So, an equivalent dataset for the correct solution in the other thread could be created as:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data viewcomp1;
do _n_=1 to 26;
  view1='Success'; view2='Success';
  count=1;
  output;
end;
do _n_=1 to 4;
  view1='Success'; view2='Failure';
  count=1;
  output;
end;
view1='Failure';
count=0;
output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN class=""&gt;(Note that the value of VIEW2 in the last observation is 'Failure' from the preceding DO loop, but 'Success' would be fine as well. Even a missing value would work.)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;Now the correct result can be replicated with:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data = viewcomp1;
weight count / zeros;
tables view1*view2 / agree;
exact mcnem;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Obviously, the DATA step above could be simplified to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data viewcomp1;
view1='Success';
count=1;
do _n_=1 to 26;
  view2=view1;
  output;
end;
do _n_=1 to 4;
  view2='Failure';
  output;
end;
view1=view2;
count=0;
output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Jan 2019 18:39:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/McNemar-Test-with-a-Zero-Cell/m-p/524641#M73507</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-01-04T18:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: McNemar Test with a Zero Cell</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/McNemar-Test-with-a-Zero-Cell/m-p/525393#M73514</link>
      <description>&lt;P&gt;Thank you both&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52346"&gt;@lopezr&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;. Both of your solutions presuppose that the cell counts are known, and I didn't specify that I was looking for a solution where these counts are not known. A colleague of mine suggested the following solution and it worked, so I am including it here. Var1 and var2 are grouping variables and var3 and var4 are the variables in the 2x2 table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc means data=xxxxxx completetypes noprint nway;&lt;BR /&gt;class var1 var2&amp;nbsp;var3&amp;nbsp;var4;&lt;BR /&gt;output out=freqnew(rename=(_freq_=count) drop=_type_);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=freqnew;&lt;BR /&gt;by&amp;nbsp;var1&amp;nbsp;var2&amp;nbsp;var3&amp;nbsp;var4 _stat_ count;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data analysis (keep=var1&amp;nbsp;var2&amp;nbsp;var3&amp;nbsp;var4 count);&lt;BR /&gt;set freqnew; by var1&amp;nbsp;var2&amp;nbsp;var3&amp;nbsp;var4 _stat_ count;&lt;BR /&gt;if first.var4;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc print data=analysis noobs;&lt;BR /&gt;title1 "Zero Table Cell Added to Raw Data";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc Freq data=analysis;&lt;BR /&gt;by&amp;nbsp;var1&amp;nbsp;var2;&lt;BR /&gt;Tables var3*var4 / missing agree;&lt;BR /&gt;exact mcnem;&lt;BR /&gt;weight count / zeros;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 13:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/McNemar-Test-with-a-Zero-Cell/m-p/525393#M73514</guid>
      <dc:creator>mrprerost</dc:creator>
      <dc:date>2019-01-08T13:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: McNemar Test with a Zero Cell</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/McNemar-Test-with-a-Zero-Cell/m-p/525504#M73515</link>
      <description>&lt;P&gt;I see what you mean.&amp;nbsp;The datasets&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52346"&gt;@lopezr&lt;/a&gt;&amp;nbsp;and I produced (using hardcoded numbers of observations like 26 and 4) were just to demonstrate that the McNemar test involving zero cells can be performed without having summary data. Of course, I would not recommend creating detail data from existing summary data for this purpose, let alone using hardcoded numbers. (The required zero-weight observation could have been appended without knowing these numbers.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that your PROC MEANS approach (using the COMPLETETYPES option) would &lt;EM&gt;not&lt;/EM&gt; have worked in the situation of the other thread you referred to in your original post: There the problem was that the value VIEW1='Failure' did not occur in the initial dataset. COMPLETETYPES would not add it. Instead, the CLASSDATA= option could have been used (or a preloaded format), as shown below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data for demonstration */

data have;
view1='Success';
do _n_=1 to 26;
  view2=view1;
  output;
end;
do _n_=1 to 4;
  view2='Failure';
  output;
end;
run;

/* Create a class dataset in order to introduce the non-existing level of VIEW1 */

data cldat;
view1='Failure';
view2=view1;
run; /* A more general version of CLDAT could contain all four
        combinations of 'Success' and 'Failure'. */

/* Produce input dataset for PROC FREQ */

proc summary data=have classdata=cldat nway;
class view1 view2;
output out=want;
run;

/* Perform the desired McNemar test */

proc freq data = want;
weight _freq_ / zeros;
tables view1*view2 / agree;
exact mcnem;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Jan 2019 17:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/McNemar-Test-with-a-Zero-Cell/m-p/525504#M73515</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-01-08T17:46:37Z</dc:date>
    </item>
  </channel>
</rss>

