In reply to Ksharp.

Thanks for the comment. I understand your concerns, and your DATA step solution is worth looking at if
1) The indicator matrix is on disk as a SAS data set
2) You want the pairwise counts in a data set.
However, the SAS/IML solution is useful when the raw data are in a SAS/IML matrix and you need to
(A) form the indicator matrix and (B) count the pairwise relationships.

You claim that the crossproduct matrix will "cost many times when you have ten thousands of variables," but that assertion does not agree with timings that I ran. Matrix multiplication will be faster on multi-core machines with a math kernel library (provided, of course, that everything fits in RAM). For example, on my desktop PC the IML solution for 2000 variables takes about 3 seconds, whereas the DATA step and PROC FREQ solution takes about 8 minutes=240 seconds. For 5000 variables, the IML solution takes 11 seconds. I tried to time the DATA step/FREQ solution for 5000 variables, but I eventually gave up. Try it on the following example. I think you run IML under SAS University Edition, so you probably won't get the MKL performance boost.

data have;
array x[2000];
do i = 1 to 20000;
do j = 1 to dim(x);
x[j] = rand("Bern", 0.05);
end;
output;
end;
drop i j;
run;

proc iml;
t0 = time();
use have;
read all var _num_ into C;
close;
P = C`*C;
t1 = time()-t0;
print t1;
quit;

/* put your DATA step and PROC FREQ steps here */