<?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: Computing multiway tables using indexed variables and proc freq in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/772883#M245438</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/366153"&gt;@docfak&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is interesting! Even with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select CochransQ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is more restrictive than&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods exclude crosstabfreqs;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PROC FREQ would probably take a while to run your code with this 1000-obs. sample dataset HAVE (in place of your MYDATA)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let m=24;

data have;
call streaminit(27182818);
array var[&amp;amp;m];
do i=1 to 1000;
  do _n_=1 to dim(var);
    var[_n_]=rand('bern',0.5);
  end;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I haven't actually run your PROC FREQ step with &lt;FONT face="courier new,courier"&gt;m=24&lt;/FONT&gt;, but observed that for &lt;FONT face="courier new,courier"&gt;m=17, 18, 19, 20&lt;/FONT&gt; the run times approximately doubled with each additional variable (like 5, 9, 19, 39 seconds).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I looked up the formula for Cochran's Q (and the associated p-value) in the most recent SAS 9.4 documentation (&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_freq_details78.htm" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_freq_details78.htm&lt;/A&gt;). After some more research and manual calculations I realized that &lt;EM&gt;the&amp;nbsp;formula for Cochran's Q on that page (and in my local SAS 9.4M5 help files) is wrong!&lt;/EM&gt; I will report this to SAS. Comparing older versions of the documentation, starting at SAS version 8 (&lt;A href="http://v8doc.sas.com/sashtml/proc/zeq-comp.htm" target="_blank" rel="noopener"&gt;http://v8doc.sas.com/sashtml/proc/zeq-comp.htm&lt;/A&gt;), it appears that the error was introduced in the documentation of SAS 9.&lt;EM&gt;2&lt;/EM&gt; (&lt;A href="https://support.sas.com/documentation/cdl/en/procstat/63104/HTML/default/viewer.htm#procstat_freq_a0000000665.htm" target="_blank" rel="noopener"&gt;https://support.sas.com/documentation/cdl/en/procstat/63104/HTML/default/viewer.htm#procstat_freq_a0000000665.htm&lt;/A&gt;) and then copied to versions 9.3 and 9.4. In version 8 and also as "recently" as v9.1.3 (&lt;A href="https://support.sas.com/documentation/onlinedoc/91pdf/index_913.html" target="_blank" rel="noopener"&gt;https://support.sas.com/documentation/onlinedoc/91pdf/index_913.html&lt;/A&gt;, see Procedures Guide base_proc_8977.pdf linked there) the formula was correct:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Correct formula in SAS 9.1.3 Procedures Guide, p. 1621" style="width: 336px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64493iA211F6510A7168BB/image-size/large?v=v2&amp;amp;px=999" role="button" title="CQ_v9.1.3.png" alt="Correct formula in SAS 9.1.3 Procedures Guide, p. 1621" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Correct formula in SAS 9.1.3 Procedures Guide, p. 1621&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Incorrect formula in SAS 9.4/Viya 3.5 documentation" style="width: 663px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64494iD7611E8D145C9A0D/image-size/large?v=v2&amp;amp;px=999" role="button" title="CQ_v9.2-9.4.png" alt="Incorrect formula in SAS 9.4/Viya 3.5 documentation" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Incorrect formula in SAS 9.4/Viya 3.5 documentation&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Using the correct formula (more precisely: a formula equivalent to the correct one) I was able to reproduce the results from PROC FREQ for&amp;nbsp;&lt;FONT face="courier new,courier"&gt;m=17, 18, 19, 20&lt;/FONT&gt;, but with run times &amp;lt;1 second, and the case &lt;FONT face="courier new,courier"&gt;m=24&lt;/FONT&gt; went about as fast as the others. Here's the code I used:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
ods output onewayfreqs=freqs;
proc freq data=have;
tables var:;
run;
ods select all;

data freqs1(keep=n);
set freqs(rename=(frequency=n));
if sum(of var:);
run;

proc summary data=freqs1;
var n;
output out=stats(drop=_:) css=c sum=t;
run;

data want(keep=s c t Q DF p);
do until(last);
  set have end=last;
  s+(sum(of var:)**2);
end;
set stats;
Q=(&amp;amp;m-1)*c/(t-s/&amp;amp;m);
DF=&amp;amp;m-1;
p=1-cdf('chisq',Q,DF);
format p pvalue6.4;
label Q="Cochran's Q"
      p="p-value of Cochran's Q test";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log (incl. creation of sample data)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;1    %let m=24;
2
3    data have;
4    call streaminit(27182818);
5    array var[&amp;amp;m];
6    do i=1 to 1000;
7      do _n_=1 to dim(var);
8        var[_n_]=rand('bern',0.5);
9      end;
10     output;
11   end;
12   run;

NOTE: The data set WORK.HAVE has 1000 observations and 25 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


13
14   ods select none;
15   ods output onewayfreqs=freqs;
16   proc freq data=have;
17   tables var:;
18   run;

NOTE: The data set WORK.FREQS has 48 observations and 53 variables.
NOTE: There were 1000 observations read from the data set WORK.HAVE.
NOTE: PROCEDURE FREQ used (Total process time):
      real time           0.09 seconds
      cpu time            0.09 seconds


19   ods select all;
20
21   data freqs1(keep=n);
22   set freqs(rename=(frequency=n));
23   if sum(of var:);
24   run;

NOTE: There were 48 observations read from the data set WORK.FREQS.
NOTE: The data set WORK.FREQS1 has 24 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


25
26   proc summary data=freqs1;
27   var n;
28   output out=stats(drop=_:) css=c sum=t;
29   run;

NOTE: Multiple concurrent threads will be used to summarize data.
NOTE: There were 24 observations read from the data set WORK.FREQS1.
NOTE: The data set WORK.STATS has 1 observations and 2 variables.
NOTE: PROCEDURE SUMMARY used (Total process time):
      real time           0.03 seconds
      cpu time            0.07 seconds


30
31   data want(keep=s c t Q DF p);
32   do until(last);
33     set have end=last;
34     s+(sum(of var:)**2);
35   end;
36   set stats;
37   Q=(&amp;amp;m-1)*c/(t-s/&amp;amp;m);
38   DF=&amp;amp;m-1;
39   p=1-cdf('chisq',Q,DF);
40   format p pvalue6.4;
41   label Q="Cochran's Q"
42         p="p-value of Cochran's Q test";
43   run;

NOTE: There were 1000 observations read from the data set WORK.HAVE.
NOTE: There were 1 observations read from the data set WORK.STATS.
NOTE: The data set WORK.WANT has 1 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;Result (dataset WANT)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;   s         c              t       Q       DF         p

152459    4314.96       12097    17.2762    23    0.7955&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, if you only need Cochran's Q and the associated p-value, it seems that the manual calculation beats PROC FREQ.&lt;/P&gt;</description>
    <pubDate>Thu, 07 Oct 2021 21:09:26 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-10-07T21:09:26Z</dc:date>
    <item>
      <title>Computing multiway tables using indexed variables and proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/772760#M245398</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to compute a Cochran's Q using proc freq with 24 indexed variables, but SAS freezes as I think the line of code is too long.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a trick to allow SAS to compute the line of code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=mydata;
tables var1*var2*var3*var4*var5*var6*var7*var8*var9*var10*var11*var12*var13*var14*var15*var16*var17*var18*var19*var20*var21*var22*var23*var24 /agree;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Many thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 14:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/772760#M245398</guid>
      <dc:creator>docfak</dc:creator>
      <dc:date>2021-10-07T14:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: Computing multiway tables using indexed variables and proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/772814#M245409</link>
      <description>&lt;P&gt;How many levels are involved with each of those variables? IF you have 2 levels per variable you are looking at 2**22 (4,194,304) 2-by-2 tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Freeze" in this case, I would guess means &lt;STRONG&gt;you&lt;/STRONG&gt; don't see anything because SAS is making all those html tables to display all of the frequencies involved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I might suggest placing this immediately before your Proc Freq code to suppress the humoungous&lt;/P&gt;
&lt;PRE&gt;ods exclude crosstabfreqs;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure that your data meets the requirements for Agreement calculations as in " AGREE statistics are computed only for tables where the number of rows equals the number of columns." ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 17:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/772814#M245409</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-07T17:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: Computing multiway tables using indexed variables and proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/772819#M245413</link>
      <description>&lt;P&gt;I have two levels per variable.&lt;/P&gt;&lt;P&gt;When I use 12 variables (var1-var12), I can compute Cochran's Q.&lt;/P&gt;&lt;P&gt;Using your line of code, I get this error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR:  An exception has been encountered.
Veuillez contacter le support technique et transmettez-lui les informations suivantes :

Le nom de la tâche SAS est [FREQ]
ERROR:  Violation de l'accès en lecture FREQ
Exception en (0753146E)
Task Traceback
Address   Frame     (DBGHELP API Version 4.0 rev 5)
000000000753146E  00000000007F9F70  sasods:tkvercn1+0x10042E
000000000753CD31  00000000007FA2E0  sasods:tkvercn1+0x10BCF1
000000000753C30A  00000000007FA370  sasods:tkvercn1+0x10B2CA
000000000F604DB5  00000000007FA378  sasfreq:tkvercn1+0x73D75
000000000F5B177D  00000000007FCC60  sasfreq:tkvercn1+0x2073D
000000000F59450B  00000000007FFB20  sasfreq:tkvercn1+0x34CB
00000000035BA366  00000000007FFB28  sashost:Main+0x11EA6
00000000035C0574  00000000007FFF20  sashost:Main+0x180B4
00007FFCCAD07034  00000000007FFF28  KERNEL32:BaseThreadInitThunk+0x14
00007FFCCB422651  00000000007FFF58  ntdll:RtlUserThreadStart+0x21&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 17:19:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/772819#M245413</guid>
      <dc:creator>docfak</dc:creator>
      <dc:date>2021-10-07T17:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Computing multiway tables using indexed variables and proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/772883#M245438</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/366153"&gt;@docfak&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is interesting! Even with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select CochransQ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is more restrictive than&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods exclude crosstabfreqs;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PROC FREQ would probably take a while to run your code with this 1000-obs. sample dataset HAVE (in place of your MYDATA)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let m=24;

data have;
call streaminit(27182818);
array var[&amp;amp;m];
do i=1 to 1000;
  do _n_=1 to dim(var);
    var[_n_]=rand('bern',0.5);
  end;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I haven't actually run your PROC FREQ step with &lt;FONT face="courier new,courier"&gt;m=24&lt;/FONT&gt;, but observed that for &lt;FONT face="courier new,courier"&gt;m=17, 18, 19, 20&lt;/FONT&gt; the run times approximately doubled with each additional variable (like 5, 9, 19, 39 seconds).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I looked up the formula for Cochran's Q (and the associated p-value) in the most recent SAS 9.4 documentation (&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_freq_details78.htm" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_freq_details78.htm&lt;/A&gt;). After some more research and manual calculations I realized that &lt;EM&gt;the&amp;nbsp;formula for Cochran's Q on that page (and in my local SAS 9.4M5 help files) is wrong!&lt;/EM&gt; I will report this to SAS. Comparing older versions of the documentation, starting at SAS version 8 (&lt;A href="http://v8doc.sas.com/sashtml/proc/zeq-comp.htm" target="_blank" rel="noopener"&gt;http://v8doc.sas.com/sashtml/proc/zeq-comp.htm&lt;/A&gt;), it appears that the error was introduced in the documentation of SAS 9.&lt;EM&gt;2&lt;/EM&gt; (&lt;A href="https://support.sas.com/documentation/cdl/en/procstat/63104/HTML/default/viewer.htm#procstat_freq_a0000000665.htm" target="_blank" rel="noopener"&gt;https://support.sas.com/documentation/cdl/en/procstat/63104/HTML/default/viewer.htm#procstat_freq_a0000000665.htm&lt;/A&gt;) and then copied to versions 9.3 and 9.4. In version 8 and also as "recently" as v9.1.3 (&lt;A href="https://support.sas.com/documentation/onlinedoc/91pdf/index_913.html" target="_blank" rel="noopener"&gt;https://support.sas.com/documentation/onlinedoc/91pdf/index_913.html&lt;/A&gt;, see Procedures Guide base_proc_8977.pdf linked there) the formula was correct:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Correct formula in SAS 9.1.3 Procedures Guide, p. 1621" style="width: 336px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64493iA211F6510A7168BB/image-size/large?v=v2&amp;amp;px=999" role="button" title="CQ_v9.1.3.png" alt="Correct formula in SAS 9.1.3 Procedures Guide, p. 1621" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Correct formula in SAS 9.1.3 Procedures Guide, p. 1621&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Incorrect formula in SAS 9.4/Viya 3.5 documentation" style="width: 663px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64494iD7611E8D145C9A0D/image-size/large?v=v2&amp;amp;px=999" role="button" title="CQ_v9.2-9.4.png" alt="Incorrect formula in SAS 9.4/Viya 3.5 documentation" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Incorrect formula in SAS 9.4/Viya 3.5 documentation&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Using the correct formula (more precisely: a formula equivalent to the correct one) I was able to reproduce the results from PROC FREQ for&amp;nbsp;&lt;FONT face="courier new,courier"&gt;m=17, 18, 19, 20&lt;/FONT&gt;, but with run times &amp;lt;1 second, and the case &lt;FONT face="courier new,courier"&gt;m=24&lt;/FONT&gt; went about as fast as the others. Here's the code I used:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
ods output onewayfreqs=freqs;
proc freq data=have;
tables var:;
run;
ods select all;

data freqs1(keep=n);
set freqs(rename=(frequency=n));
if sum(of var:);
run;

proc summary data=freqs1;
var n;
output out=stats(drop=_:) css=c sum=t;
run;

data want(keep=s c t Q DF p);
do until(last);
  set have end=last;
  s+(sum(of var:)**2);
end;
set stats;
Q=(&amp;amp;m-1)*c/(t-s/&amp;amp;m);
DF=&amp;amp;m-1;
p=1-cdf('chisq',Q,DF);
format p pvalue6.4;
label Q="Cochran's Q"
      p="p-value of Cochran's Q test";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log (incl. creation of sample data)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;1    %let m=24;
2
3    data have;
4    call streaminit(27182818);
5    array var[&amp;amp;m];
6    do i=1 to 1000;
7      do _n_=1 to dim(var);
8        var[_n_]=rand('bern',0.5);
9      end;
10     output;
11   end;
12   run;

NOTE: The data set WORK.HAVE has 1000 observations and 25 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


13
14   ods select none;
15   ods output onewayfreqs=freqs;
16   proc freq data=have;
17   tables var:;
18   run;

NOTE: The data set WORK.FREQS has 48 observations and 53 variables.
NOTE: There were 1000 observations read from the data set WORK.HAVE.
NOTE: PROCEDURE FREQ used (Total process time):
      real time           0.09 seconds
      cpu time            0.09 seconds


19   ods select all;
20
21   data freqs1(keep=n);
22   set freqs(rename=(frequency=n));
23   if sum(of var:);
24   run;

NOTE: There were 48 observations read from the data set WORK.FREQS.
NOTE: The data set WORK.FREQS1 has 24 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


25
26   proc summary data=freqs1;
27   var n;
28   output out=stats(drop=_:) css=c sum=t;
29   run;

NOTE: Multiple concurrent threads will be used to summarize data.
NOTE: There were 24 observations read from the data set WORK.FREQS1.
NOTE: The data set WORK.STATS has 1 observations and 2 variables.
NOTE: PROCEDURE SUMMARY used (Total process time):
      real time           0.03 seconds
      cpu time            0.07 seconds


30
31   data want(keep=s c t Q DF p);
32   do until(last);
33     set have end=last;
34     s+(sum(of var:)**2);
35   end;
36   set stats;
37   Q=(&amp;amp;m-1)*c/(t-s/&amp;amp;m);
38   DF=&amp;amp;m-1;
39   p=1-cdf('chisq',Q,DF);
40   format p pvalue6.4;
41   label Q="Cochran's Q"
42         p="p-value of Cochran's Q test";
43   run;

NOTE: There were 1000 observations read from the data set WORK.HAVE.
NOTE: There were 1 observations read from the data set WORK.STATS.
NOTE: The data set WORK.WANT has 1 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;Result (dataset WANT)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;   s         c              t       Q       DF         p

152459    4314.96       12097    17.2762    23    0.7955&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, if you only need Cochran's Q and the associated p-value, it seems that the manual calculation beats PROC FREQ.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 21:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/772883#M245438</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-10-07T21:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: Computing multiway tables using indexed variables and proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/773271#M245623</link>
      <description>&lt;P&gt;This is very interesting, thank you very much!&lt;/P&gt;</description>
      <pubDate>Sun, 10 Oct 2021 16:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/773271#M245623</guid>
      <dc:creator>docfak</dc:creator>
      <dc:date>2021-10-10T16:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: Computing multiway tables using indexed variables and proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/773281#M245628</link>
      <description>&lt;P&gt;Why do you think those two different ways of writing the formula are different?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 336px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64562iD2F1051C49F5DC59/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Is of the form A*((B*C)/D)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 663px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64563i84D64715913479CF/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Has the same terms re-arranged into: B*A*C/D&lt;/P&gt;</description>
      <pubDate>Sun, 10 Oct 2021 18:29:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/773281#M245628</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-10-10T18:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: Computing multiway tables using indexed variables and proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/773291#M245632</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;, for chiming in. I see what you mean, but my understanding is that the term &lt;EM&gt;T²&lt;/EM&gt; is not part of the sum (&lt;EM&gt;j=&lt;/EM&gt;1, ..., &lt;EM&gt;m&lt;/EM&gt;) because it doesn't contain &lt;EM&gt;j&lt;/EM&gt; and it's not enclosed in parentheses either. (Also, I think that my "manual" calculation is consistent with this interpretation and its results matched those from PROC FREQ in the few cases I checked.) So, multiplying &lt;EM&gt;m&lt;/EM&gt; (from the second form of the equation) into the numerator of the fraction would result in &lt;EM&gt;m&lt;FONT face="symbol"&gt;S&lt;/FONT&gt;T&lt;SUB&gt;j&lt;/SUB&gt;² − &lt;FONT color="#FF0000"&gt;m&lt;/FONT&gt;T²&lt;/EM&gt;, but the correct term is&amp;nbsp;&lt;EM&gt;m&lt;FONT face="symbol"&gt;S&lt;/FONT&gt;T&lt;SUB&gt;j&lt;/SUB&gt;² − T²&lt;/EM&gt;&amp;nbsp;(as in the first equation).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have sent a notification to SAS via the "Feedback" link on the documentation page and I will report their response (if any) in this thread.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Addendum:&lt;/P&gt;
&lt;P&gt;Another strong argument supporting my point is:&lt;/P&gt;
&lt;P&gt;We have &lt;EM&gt;T=&lt;FONT face="symbol"&gt;S&lt;/FONT&gt;T&lt;SUB&gt;j&lt;/SUB&gt;&lt;/EM&gt;&amp;nbsp;and, by Cauchy-Schwarz inequality,&lt;I&gt; &lt;/I&gt;&lt;EM&gt;T²&amp;nbsp;≤&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;m&lt;FONT face="symbol"&gt;S&lt;/FONT&gt;T&lt;SUB&gt;j&lt;/SUB&gt;²&amp;nbsp;&lt;/EM&gt;&amp;nbsp;(with equality holding in the case &lt;EM&gt;T&lt;SUB&gt;1&lt;/SUB&gt;=...=T&lt;SUB&gt;m&lt;/SUB&gt;&lt;/EM&gt;), so the numerator of the fraction in the old (correct) version of the formula (as I read it) is non-negative. The denominator is&amp;nbsp;non-negative as well because&amp;nbsp;&lt;EM&gt;T=&lt;FONT face="symbol"&gt;S&lt;FONT face="arial,helvetica,sans-serif"&gt;S&lt;SUB&gt;k&lt;/SUB&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/EM&gt;&amp;nbsp;and 0&lt;EM&gt;&amp;nbsp;≤ S&lt;SUB&gt;k&lt;/SUB&gt;&amp;nbsp;≤ m &lt;/EM&gt;for all &lt;EM&gt;k=&lt;/EM&gt;1&lt;EM&gt;, ..., N&lt;/EM&gt;, which implies&amp;nbsp;&lt;EM&gt;mT ≥&lt;FONT face="symbol"&gt;S&lt;/FONT&gt;S&lt;SUB&gt;k&lt;/SUB&gt;²&amp;nbsp;&lt;/EM&gt;(with equality holding in the case &lt;EM&gt;S&lt;SUB&gt;1,&amp;nbsp;&lt;/SUB&gt;..., S&lt;SUB&gt;N&lt;/SUB&gt;&lt;/EM&gt;&amp;nbsp;&lt;FONT face="symbol"&gt;Î&lt;/FONT&gt; {0, &lt;EM&gt;m&lt;/EM&gt;}). Hence, &lt;EM&gt;Q&lt;SUB&gt;C&lt;/SUB&gt;&lt;/EM&gt; cannot be negative, which is plausible as it is a chi-square statistic. However, the numerator of the new (incorrect) formula is non-positive (since&amp;nbsp;&lt;EM&gt;&lt;FONT face="symbol"&gt;S&lt;/FONT&gt;T&lt;SUB&gt;j&lt;/SUB&gt;²&amp;nbsp;≤&amp;nbsp;(&lt;FONT face="symbol"&gt;S&lt;/FONT&gt;T&lt;SUB&gt;j&lt;/SUB&gt;)² = T²&lt;/EM&gt;), even regardless of &lt;EM&gt;T²&lt;/EM&gt; being part of the sum or not. Together with the non-negative denominator&amp;nbsp;&lt;EM&gt;Q&lt;SUB&gt;C&lt;/SUB&gt;&lt;/EM&gt; could never be positive, which would be absurd for a&amp;nbsp;chi-square statistic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Oct 2021 18:51:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/773291#M245632</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-10-11T18:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Computing multiway tables using indexed variables and proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/838432#M331503</link>
      <description>&lt;P&gt;&lt;U&gt;Update 2022-10-13&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have not received any response from SAS to my notifications regarding the Cochran's &lt;EM&gt;Q&lt;/EM&gt; formula in question (emails to yourturn@sas.com sent on October 10, 2021 and June 11, 2022), and the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_freq_details78.htm" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt; has not been revised either. This must be a rare exception because in&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Certification/SAS-Certifiication-amp-Documentation-Questions/m-p/800738/highlight/true#M1248" target="_blank" rel="noopener"&gt;Re: SAS Certifiication &amp;amp; Documentation Questions&lt;/A&gt;&amp;nbsp;(March 2022) it says: "&lt;SPAN&gt;Our team responds to every request within 2 business days."&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2022 16:14:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/838432#M331503</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-10-13T16:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Computing multiway tables using indexed variables and proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/838517#M331536</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/208935"&gt;@free&lt;/a&gt;. You're right...unanswered feedback from our team is a rare exception. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; I'm on the team that monitors the &lt;A href="mailto:yourturn@sas.com" target="_blank"&gt;yourturn@sas.com&lt;/A&gt;&amp;nbsp;inbox and we're committed to addressing each response we receive. I don't see your feedback emails on this topic from the dates you mention (10/10/21 and 6/11/22). I wonder if there was an email delivery snafu.&lt;/P&gt;
&lt;P&gt;Regardless, I'd like to be sure we address your feedback. I will inform our team about this Communities thread to investigate the doc. In the meantime, please feel free to send another email to &lt;A href="mailto:yourturn@sas.com" target="_blank"&gt;yourturn@sas.com&lt;/A&gt;&amp;nbsp;about this same issue so we can be sure your emails are delivering accurately.&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2022 20:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/838517#M331536</guid>
      <dc:creator>MarkBright</dc:creator>
      <dc:date>2022-10-13T20:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Computing multiway tables using indexed variables and proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/838522#M331538</link>
      <description>&lt;P&gt;Many thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/93260"&gt;@MarkBright&lt;/a&gt;, for your prompt response. Indeed, lost emails were my only explanation for this. I'm going to re-send the email from last June.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2022 21:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/838522#M331538</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-10-13T21:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: Computing multiway tables using indexed variables and proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/839080#M331756</link>
      <description>&lt;P&gt;&lt;U&gt;Update 2022-10-17&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The typo in Cochran's&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;Q&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;formula in the current PROC FREQ documentation was &lt;EM&gt;confirmed&lt;/EM&gt; by SAS Technical Support earlier today (and indeed within two business days after I had re-sent the lost email). The correction (replacement of &lt;EM&gt;T²&lt;/EM&gt; by &lt;EM&gt;T²/m&lt;/EM&gt;) will be made "in the next release of the documentation."&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 21:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-multiway-tables-using-indexed-variables-and-proc-freq/m-p/839080#M331756</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-10-17T21:12:37Z</dc:date>
    </item>
  </channel>
</rss>

