BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mt88
Calcite | Level 5

Hello,

I used the following code...

 

ods output chisq=tst;
proc freq data = combinedIDmanu;
tables fentanyl*num_doc_vis_catB/chisq;
run;

 

to send this results table:

StatisticDFValueProb
Chi-Square20.94990.6219
Likelihood Ratio Chi-Square21.70520.4263
Mantel-Haenszel Chi-Square10.34860.5549
Phi Coefficient 0.0812 
Contingency Coefficient 0.081 
Cramer's V 0.0812 
WARNING: 50% of the cells have expected counts less than 5. Chi-Square may not be a valid test.

 

to a dataset with the following fields:

TableStatisticDFValueProb
Table fentanyl * num_doc_vis_catBChi-Square20.94990.6219
Table fentanyl * num_doc_vis_catBLikelihood Ratio Chi-Square21.70520.4263
Table fentanyl * num_doc_vis_catBMantel-Haenszel Chi-Square10.34860.5549
Table fentanyl * num_doc_vis_catBPhi Coefficient_0.0812_
Table fentanyl * num_doc_vis_catBContingency Coefficient_0.081_
Table fentanyl * num_doc_vis_catBCramer's V_0.0812_

 

Is there a way to use the ods statement so that this part of the results table:

WARNING: 50% of the cells have expected counts less than 5. Chi-Square may not be a valid test.

is added to the dataset?

 

Thank you.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

SAS doesn't appear to expose that message to ODS output.

 

If I had to do such I would also output the crosstabfreqs such as:

ods output chisq=tst
           crosstabfreqs=freqs;

Then summarize the small cell counts:

Proc format library=work;
value _5freq
0-<5= '<5'
5<-high ='5+'
;
proc freq data=freqs;
   /* this where for a simple example like this 
   gets the cells from the  body of the table
   */
   where _type_='11';
   tables frequency /out=freqpct;
   format frequency _5freq.;
run;

and use that Freqpct data to create whatever you think should be added to that Chi square result set.

 

 

View solution in original post

2 REPLIES 2
ballardw
Super User

SAS doesn't appear to expose that message to ODS output.

 

If I had to do such I would also output the crosstabfreqs such as:

ods output chisq=tst
           crosstabfreqs=freqs;

Then summarize the small cell counts:

Proc format library=work;
value _5freq
0-<5= '<5'
5<-high ='5+'
;
proc freq data=freqs;
   /* this where for a simple example like this 
   gets the cells from the  body of the table
   */
   where _type_='11';
   tables frequency /out=freqpct;
   format frequency _5freq.;
run;

and use that Freqpct data to create whatever you think should be added to that Chi square result set.

 

 

FreelanceReinh
Jade | Level 19

Hello @mt88,

 

You could use PROC SQL to add a constant variable to the ODS output dataset containing the percentage of cells with expected frequency less than 5:

ods output chisq=tst crosstabfreqs=ctf;
proc freq data = combinedIDmanu;
tables fentanyl*num_doc_vis_catB/chisq expected;
run;

proc sql;
create table want as
select * 
from tst, (select mean(.<expected<5) as expected_lt_5 format=percent6.0
           from ctf
           where _type_='11');
quit;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 500 views
  • 0 likes
  • 3 in conversation