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:
| Statistic | DF | Value | Prob |
| Chi-Square | 2 | 0.9499 | 0.6219 |
| Likelihood Ratio Chi-Square | 2 | 1.7052 | 0.4263 |
| Mantel-Haenszel Chi-Square | 1 | 0.3486 | 0.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:
| Table | Statistic | DF | Value | Prob |
| Table fentanyl * num_doc_vis_catB | Chi-Square | 2 | 0.9499 | 0.6219 |
| Table fentanyl * num_doc_vis_catB | Likelihood Ratio Chi-Square | 2 | 1.7052 | 0.4263 |
| Table fentanyl * num_doc_vis_catB | Mantel-Haenszel Chi-Square | 1 | 0.3486 | 0.5549 |
| Table fentanyl * num_doc_vis_catB | Phi Coefficient | _ | 0.0812 | _ |
| Table fentanyl * num_doc_vis_catB | Contingency Coefficient | _ | 0.081 | _ |
| Table fentanyl * num_doc_vis_catB | Cramer'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.
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.
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.
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.