proc IML;
agegroup = {"<=34",">34"};
status = {"Single" "Married" "Divorced"};
counts ={25 15 0,
2 9 3};
p = counts / sum(counts);
print p[colname=status
rowname=agegroup
label="Marital Status by Age Group"
format=percent7.1];
proc freq data=counts order=data;
tables agegroup*status / expected cellchi2 norow nocol chisq;
output out=ChiSqData n nmiss pchi lrchi;
weight Count;
title 'Chi-Square Tests for 3 by 5 Table of Eye and Hair Color';
run;
proc print data=ChiSqData noobs;
title1 'Chi-Square Statistics for agegroup and status';
title2 'Output Data Set from the FREQ Procedure';
run;
proc freq
agegroup = {"<=34",">34"};
status = {"Single" "Married" "Divorced"};
counts ={25 15 0,
2 9 3};
tables agegroupr *status
/ chisq;
weight counts;
run;
I have found two code of independence test. But the form of original data,first passage, is not the same with the data which I have found. So who can tell me how to correct one of them or both.
The first set of statement in PROC IML do not run any tests. They just print the proportions for a table.
The second set of statement require a SAS data set called COUNTS that contains the data. The code runs some tests for association on that data, but be warned that the chi-square test is not recommended for tables with small cell counts.
The third set of statements doesn't make sense and is not valid.
Perhaps the following DATA set and PROC FREQ statement will help get you started:
data counts;
length agegroup $5. status $10.;
input agegroup $ status $ count;
datalines;
Young Single 25
Young Married 15
Young Divorced 0
Older Single 2
Older Married 9
Older Divorced 3
;
proc freq data=counts order=data;
tables agegroup*status / norow nocol chisq;
weight Count;
run;
The first set of statement in PROC IML do not run any tests. They just print the proportions for a table.
The second set of statement require a SAS data set called COUNTS that contains the data. The code runs some tests for association on that data, but be warned that the chi-square test is not recommended for tables with small cell counts.
The third set of statements doesn't make sense and is not valid.
Perhaps the following DATA set and PROC FREQ statement will help get you started:
data counts;
length agegroup $5. status $10.;
input agegroup $ status $ count;
datalines;
Young Single 25
Young Married 15
Young Divorced 0
Older Single 2
Older Married 9
Older Divorced 3
;
proc freq data=counts order=data;
tables agegroup*status / norow nocol chisq;
weight Count;
run;
Can I ask the meaning of " order= data" and " weight Count" ? I've consulted the directions but still confused.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.