Categories: Tools & Techniques

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

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


Good Rich 85

Good Poor 165

Bad Rich 75

Bad Poor 175


proc freq data=economic;

tables Status*Condition/chisq norow nocol nopercent expected;

weight n;

proc print;


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.
Jigsaw’s Data Science with SAS Course – click here.
Jigsaw’s Data Science with R Course – click here.
Jigsaw’s Big Data Course – click here.
Kafeel Basha

Published by
Kafeel Basha

Recent Posts

Books on Analytics

Analytics is a vast field. At the one end, it overlaps with statistics and higher…

Career in analytics in a KPO

Do you love to explore and investigate information? Do you find spreadsheets to be a…

Indian companies using analytics

India has developed into the global hub for analytics. A large number of MNCs have…

IBM: Betting big on analytics

International Business Machines Corp. Or IBM as it is popularly known recently announced its restructuring…

How to build a successful career in analytics

So you have got a job as an analyst in your dream company? Here are…

What’s the sentiment on “sentiment analysis”?

What's the sentiment on "sentiment analysis"? Is the field ready to take off?