By: Kafeel Basha- Jigsaw Academy Faculty

In my first post ANOVA & Chi Square Using the Language of SAS- Part 1 we looked at some of the procedures involved in analysing ANOVA & Chi square using SAS. I went on to explain ANOVA and give you many examples of how ANOVA is used to determine the significant differences between the means of three or more independent distinct groups, how it compares the means between the groups you are interested in and determines whether any of those means are significantly different from each other and finally how it is used to determine the significant differences between the means of three or more independent distinct groups with unequal sample size.
In this post I will talk about Chi square test using SAS ®
Chi square test using SAS ®

A chi square (X2) statistic is used to investigate whether distributions of categorical variables differ from one another. Basically categorical variable yield data in the categories and numerical variables yield data in numerical form. There are basically two types of random variables and they yield two types of data: numerical and categorical.

There are several types of chi square tests depending on the way the data was collected and the hypothesis being tested. We’ll begin with the simplest case: a 2 x 2 contingency table.
To implement a chi square test, all we need to do is add the CHISQ option to a frequency procedure. To test whether proportions within a categorical value against a hypothesis, we use the following syntax:

PROC FREQ DATA = datasetname;
TABLES variable_of_interest / chisq;
Weight n;
RUN;
Where chisq is used to perform chisquare test. The weight statement specifies each variable contains weights for each observation(cells)
Note: n should be numeric. If we don’t specify weight then SAS will take default value 1 as cell values.
Problem1:Chitest
To From the following data, test whether there is any association between economic condition and intelligence. At 0.05 level of significance what is the conclusion?

Solution using SAS.

Null Hypothesis: There is an association between the economic condition and intelligence.

Alt. Hypothesis: There is no association between the economic condition and intelligence.

We have sorted the table data as follows.

data economic;

input Condition\$ Status\$ n;

Datalines;

Good Rich 85

Good Poor 165

;run;

proc freq data=economic;

tables Status*Condition/chisq norow nocol nopercent expected;

weight n;

proc print;

run; These results show that economic condition and intelligence does not differ significantly (chi-square with 1 degrees of freedom = 0.9191, p =0.3377). Accept Null.

Note: The /chisq norow nocol nopercent line indicates that row and column percentages should not be shown.

Related Articles:

What’s New in SAS®? Another upgrade to SAS Visual Analytics.

ANOVA & Chi Square Using the Language of SAS- Part 1

Understanding and Writing SAS® Stored Process

Interested in learning about other Analytics and Big Data tools and techniques? Click on our course links and explore more. 