# SAS Chi-Square Test – SAS PROC FREQ

We offer you a brighter future with industry-ready online courses - Start Now!!

We looked at SAS t-test, correlation and regression, ANOVA in the previous tutorials, today we will be looking at another process called SAS Chi-Square test, how can we create and a two-way chi-square test in SAS Programming Language.

Moreover, we will discuss some SAS Chi-Square Test examples to under this concept better.

## What is Chi-Square Test in SAS

SASÂ Chi-Square testÂ of Independence is used to determine if there is a significant relationship between two categorical variables.

Chi-Square Testing independence determines whether two or more observations across two populations are dependent on each other (that is, whether one variable helps to estimate the other).

Testing for goodness of fit determines if an observed frequency distribution matches a theoretical frequency distribution. In both cases, the equation to calculate the chi-square statistic is where O equals the observed frequency andÂ EÂ the expected frequency.

## SAS PROC FREQ Procedure

We saw the use of PROC FREQ, to create frequency distribution tables, but it can also be used with a CHISQ option to create SAS chi-square test.

Syntax-

```PROC FREQ DATA = dataset;
TABLES variables /CHISQ TESTP=(percentage values);```

Here Percentage ValuesÂ in the TESTP statement denotes the percentage of levels of the variable.

## One Way Chi-Square Test

In the below SAS Chi-square test example, we consider a SAS chi-square test on the variable named origin in the data set SASHELP.CARS. This variable has three levels and we assign a percentage to each level.

SAS Chi-Square TestÂ Example-

```proc freq data = sashelp.cars;
tables origin /chisq
testp=(0.35 0.40 0.25);
run;```

SAS Chi Square Test

One Way Chi-Square Test Output

## Two Way Chi-Square Test

In this, two variables are used instead of one and the SAS chi-square test is applied on both of them.

Example-

```proc freq data = sashelp.cars;
tables origin*drivetrain /chisq ;
run;```

Two Way Chi-SquareÂ Test Example with Output

This was all about Chi-Square Test Tutorial. Hope you like our explanation of one way and two-way chi-square analysis in SAS Programming Language.

## Conclusion

Hope you all understood what is a chi-square test and how can we create it in SAS. We also saw a two-way chi-square test in SAS. In conclusion, we saw some SAS Chi-square test examples.

Furthermore, if you have any query feel free to ask in a comment section.Â and stay tuned to learn more interesting things in SAS.

Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

DataFlair Team

The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.