How can I display only the tables that have a significant chi-square test?


Consider a study of the analgesic effects of treatments on elderly patients with neuralgia. Two test treatments and a placebo are compared. The response variable is whether the patient reported pain or not. Researchers recorded age and gender of the patients and the duration of complaint before the treatment began. The data, consisting of 60 patients, are contained in the data set Neuralgia.

      Data Neuralgia;
         input Treatment $ Sex $ Age Duration Pain $ @@;
         datalines;
      P  F  68   1  No   B  M  74  16  No  P  F  67  30  No
      P  M  66  26  Yes  B  F  67  28  No  B  F  77  16  No
      A  F  71  12  No   B  F  72  50  No  B  F  76   9  Yes
      A  M  71  17  Yes  A  F  63  27  No  A  F  69  18  Yes
      B  F  66  12  No   A  M  62  42  No  P  F  64   1  Yes
      A  F  64  17  No   P  M  74   4  No  A  F  72  25  No
      P  M  70   1  Yes  B  M  66  19  No  B  M  59  29  No
      A  F  64  30  No   A  M  70  28  No  A  M  69   1  No
      B  F  78   1  No   P  M  83   1  Yes B  F  69  42  No
      B  M  75  30  Yes  P  M  77  29  Yes P  F  79  20  Yes
      A  M  70  12  No   A  F  69  12  No  B  F  65  14  No
      B  M  70   1  No   B  M  67  23  No  A  M  76  25  Yes
      P  M  78  12  Yes  B  M  77   1  Yes B  F  69  24  No
      P  M  66   4  Yes  P  F  65  29  No  P  M  60  26  Yes
      A  M  78  15  Yes  B  M  75  21  Yes A  F  67  11  No
      P  F  72  27  No   P  F  70  13  Yes A  M  75   6  Yes
      B  F  65   7  No   P  F  68  27  Yes P  M  68  11  Yes
      P  M  67  17  Yes  B  M  70  22  No  A  M  65  15  No
      P  F  67   1  Yes  A  M  67  10  No  P  F  72  11  Yes
      A  F  74   1  No   B  M  80  21  Yes A  F  69   3  No
      ;

The data set Neuralgia contains five variables: Treatment, Sex, Age, Duration, and Pain. The last variable, Pain, is the response variable and you would like to test the association of each of the other four variables with PAIN.

The following statement creates a macro variable, ALPHA, containing the alpha level for the tests. For this example, the alpha level is 0.05.

   %let alpha=.05;

All four tests of association can be performed in one PROC FREQ step as shown below. The ODS EXCLUDE ALL statement suppresses the display of all results. The ODS OUTPUT statement creates a SAS data set containing the results from each of the chi-square tests. The WHERE clause used in the ODS OUTPUT statement selects only the records containing a chi-square p-value less than the alpha level above. The ODS SELECT ALL statement restores display of subsequent results.

   ods exclude all;
   proc freq data=Neuralgia;
     tables Pain*(Treatment Sex Age Duration) / chisq;
     ods output chisq=out1(where=(statistic='Chi-Square' and Prob < &alpha));
     run;
   ods select all;

Next, a new macro variable, TABLES, is created to contain the table requests (such as Pain*Treatment) which yield significant results. The %LET statement initializes or resets the TABLES macro variable to a null value.

   %let tables=;
   data _null_;
     set out1;
     substr(table,1,5)='';
     call symput('tables',symget('tables')||' '||trim(left(table)));
     run;    

Finally, PROC FREQ is run a second time using the TABLES macro variable to display only those tables that are significant.

   ods exclude FishersExact;
   proc freq data=Neuralgia;
     tables &tables / chisq;
     run;

In this example, only TREATMENT and SEX have a significant association with PAIN at the alpha=0.05 level.

The FREQ Procedure

 

Frequency
Percent
Row Pct
Col Pct
Table of Pain by Treatment
PainTreatment
ABPTotal
No
15
25.00
42.86
75.00
15
25.00
42.86
75.00
5
8.33
14.29
25.00
35
58.33
 
 
Yes
5
8.33
20.00
25.00
5
8.33
20.00
25.00
15
25.00
60.00
75.00
25
41.67
 
 
Total
20
33.33
20
33.33
20
33.33
60
100.00


 

Statistics for Table of Pain by Treatment

StatisticDFValueProb
Chi-Square213.71430.0011
Likelihood Ratio Chi-Square214.02300.0009
Mantel-Haenszel Chi-Square110.11430.0015
Phi Coefficient 0.4781 
Contingency Coefficient 0.4313 
Cramer's V 0.4781 


 

Sample Size = 60

Frequency
Percent
Row Pct
Col Pct
Table of Pain by Sex
PainSex
FMTotal
No
22
36.67
62.86
73.33
13
21.67
37.14
43.33
35
58.33
 
 
Yes
8
13.33
32.00
26.67
17
28.33
68.00
56.67
25
41.67
 
 
Total
30
50.00
30
50.00
60
100.00


 

Statistics for Table of Pain by Sex

StatisticDFValueProb
Chi-Square15.55430.0184
Likelihood Ratio Chi-Square15.65440.0174
Continuity Adj. Chi-Square14.38860.0362
Mantel-Haenszel Chi-Square15.46170.0194
Phi Coefficient 0.3043 
Contingency Coefficient 0.2911 
Cramer's V 0.3043 


 

Sample Size = 60