BookmarkSubscribeRSS Feed
Lopa2016
Fluorite | Level 6

I have the following dataset on which I intend to perform a chi square test (all variables being categorical).

IndicatorAreaRange1Range2
0A17-2525-50
0A17-2525-50
0A17-2525-50
0A17-2525-50
0A0-1725-50
1A17-2525-50
1A0-1717-25
1A17-2525-50
0A17-2525-50
0A17-2525-50
0A17-2525-50
1B17-2525-50
1B17-2517-25
1B17-25U
1B17-25U
1B17-2525-50
1B17-2525-50
1B17-2525-50
1BU25-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?

3 REPLIES 3
ballardw
Super User

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.

PGStats
Opal | Level 21

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;
PG
Lopa2016
Fluorite | Level 6

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

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.

Discussion stats
  • 3 replies
  • 1365 views
  • 3 likes
  • 3 in conversation