Thanks Rick. We did try by-statement processing and it improved the speed. By 'variables' I mean 100 categorical outcome variables that are collected on each patient in a data set, each to be tested for their associations with another set of 150 subgroup variables (age group, sex, etc).. so it would amount to 15,000 separate Chi2 tests. Sorry I haven't been able to put the code here, but my question was more of a general one about whether it's computationally faster to calculate the Chi2 stats manually as in your example above, versus doing it with PROC FREQ. Do you have a sense which is quicker in general, or is the only way to test it with example code? Many thanks, Charles.