DATA Step, Macro, Functions and more

How to run independence

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

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: 3,753

Re: How to run independence

Posted in reply to karen8169

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;

View solution in original post


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

Re: How to run independence

Posted in reply to karen8169

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 213 views
  • 2 likes
  • 2 in conversation