Solved
Contributor
Posts: 43

# How to run independence

``````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.

Accepted Solutions
Solution
‎11-02-2016 02:43 PM
SAS Super FREQ
Posts: 4,237

## Re: How to run independence

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;

``````

All Replies
Solution
‎11-02-2016 02:43 PM
SAS Super FREQ
Posts: 4,237

## Re: How to run independence

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;

``````
Contributor
Posts: 43

## Re: How to run independence

Can I ask the meaning of " order= data" and " weight Count" ? I've consulted the directions but still confused.

☑ This topic is solved.