This macro encapsulates the `PROC FREQ` procedure to perform Chi-square tests (2x2 or larger contingency tables). It offers parameters to specify variables, the source table, test options (including exact tests), and output tables. The script also includes cleaning of intermediate results and display via `PROC PRINT`.
Data Analysis
Type : MIXED
The macro operates on an input table specified by the `dsn` parameter. The documentation example suggests using `sashelp.bmt`.
1 Code Block
MACRO DEFINITION Data
Explanation : Definition of the `%chisq` macro. It temporarily disables listing output (`ods listing close`), executes `PROC FREQ` with the specified options to generate result tables (`CrossTabFreqs`, `ChiSq`), cleans the frequency table via a `DATA STEP` to remove technical columns, then re-enables listing output and prints the final results.
Copied!
%macro chisq(vars, dsn, tests=chisq, outFreq=NULL, outChi=tmp,
order=freq, testOpt=, where=, by=);
* Close output to listing file/log;
ods listing close;
proc freq data=&dsn order=ℴ
tables &vars / chisq &testOpt;
exact &tests ;
where &where;
by &by;
* Output results into a dataset;
ods output CrossTabFreqs=&outFreq ChiSq=&outChi;
run;
ods listing;
* Remove some extraneous variables;
data &outFreq;
set &outFreq (drop=_TYPE_ _TABLE_);
run;
* Print the results;
proc print data=&outFreq;
run;
proc print data=&outChi;
run;
%mend chisq;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.