I have the following dataset on which I intend to perform a chi square test (all variables being categorical).
Indicator | Area | Range1 | Range2 |
0 | A | 17-25 | 25-50 |
0 | A | 17-25 | 25-50 |
0 | A | 17-25 | 25-50 |
0 | A | 17-25 | 25-50 |
0 | A | 0-17 | 25-50 |
1 | A | 17-25 | 25-50 |
1 | A | 0-17 | 17-25 |
1 | A | 17-25 | 25-50 |
0 | A | 17-25 | 25-50 |
0 | A | 17-25 | 25-50 |
0 | A | 17-25 | 25-50 |
1 | B | 17-25 | 25-50 |
1 | B | 17-25 | 17-25 |
1 | B | 17-25 | U |
1 | B | 17-25 | U |
1 | B | 17-25 | 25-50 |
1 | B | 17-25 | 25-50 |
1 | B | 17-25 | 25-50 |
1 | B | U | 25-50 |
The test is required to be perform at all levels namely for range1,range2 & area.One way to do it is to create a macro to do the same.But I have around 300 variables & to call the macro 300 times is not efficient. The code that I use for 3 variables is as follows:
options mprint mlogic symbolgen;
%macro chi_test(vars_test);
proc freq data =testdata.AllData;
tables &vars_test*Indicator/ norow nocol nopercent chisq ;
output out=stats_&vars_test &vars_test PCHI;
run;
data all_chi;
set stats_:;
run;
%mend chi_test;
%chi_test(range1);
%chi_test(range2);
%chi_test(area);
Can any one help out?
Proc freq can use _all_.
It will generate a lot of output but
tables _all_*_all_ / <your other options here>;
will work.
If there are specific variables you don't want to include such as an ID variable then use a Drop= data set option to remove them.
Use variable lists in the tables statement and ODS OUTPUT to capture the statistics
proc freq data=allData;
tables (area -- range2)*indicator / norow nocol nopercent chisq;
ods output chisq=allDataChiSq;
run;
I think a better solution would be :
data have_extra;
row+1;
set have;
run;
proc transpose data=have_extra out=tall ;
by row indicator ;
var area range1 range2 ;
run;
Then order the records by the original variable name.
proc sort; by _name_ ; run;
Then you can run your CHI-SQ for each of your original variables.
proc freq data =tall ;
by _name_;
tables col1*Indicator/ norow nocol nopercent chisq ;
output out=all_chi PCHI;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.