OK. I've modified the macro to get you what you want, as long as you don't mind a different order:
%macro doit(IN_W,IN_B,B,W,OUT);
proc sql noprint;
create table &OUT (drop = _:) as
select distinct *
from
%do I=1 %to &B;
&IN_B (keep=BLACK_NAME BLACK_VALUE
rename=(BLACK_NAME=B&I._NAME BLACK_VALUE=B&I._VALUE)) as B&I,%end;
%do J=1 %to &W;
&IN_W (keep=WHITE_NAME WHITE_VALUE
rename=(WHITE_NAME=W&J._NAME WHITE_VALUE=W&J._VALUE)) as W&J,%end;
&IN_W (obs=1 keep=WHITE_NAME rename=(WHITE_NAME=_DUMMY)) as _DUMMY
where %do I=1 %to %eval(&B-1); B&I._NAME lt B%eval(&I+1)_NAME and %end;
%do J=1 %to %eval(&W-1); W&J._NAME lt W%eval(&J+1)_NAME and %end;
1;
quit;
%mend doit;
%doit(WHITE,BLACK,2,2,WANT); * in_white, in_black, white, black, out;
The cartesian product will produce the permutations following the rules (where condition) of the results you need. For example for B=2, W=2 the macro will build the following SQL statement:
select distinct * from
BLACK (keep=BLACK_NAME BLACK_VALUE
rename=(BLACK_NAME=B1_NAME BLACK_VALUE=B1_VALUE)) as B1,
BLACK (keep=BLACK_NAME BLACK_VALUE
rename=(BLACK_NAME=B2_NAME BLACK_VALUE=B2_VALUE)) as B2,
WHITE (keep=WHITE_NAME WHITE_VALUE
rename=(WHITE_NAME=W1_NAME WHITE_VALUE=W1_VALUE)) as W1,
WHITE (keep=WHITE_NAME WHITE_VALUE
rename=(WHITE_NAME=W2_NAME WHITE_VALUE=W2_VALUE)) as W2
where B1_NAME lt B2_NAME and W1_NAME lt W2_NAME
Hope it helps. Daniel Santos @ www.cgd.pt
... View more