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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.