%macro test(n);
data test;
%do i=1 %to &n;
do v&i =1 to &n;
%if &i=1 %then %do;
tmp&i=cats("*",v&i,"*");
%end;
%else %do;
if index(tmp%eval(&i-1), cats("*",v&i,"*")) then continue;
else tmp&i="*"||catx("*",of v1-v&i)||"*";
%end;
%if &i=&n %then output;;
%end;
%do i=1 %to &n;
end;
%end;
drop tmp:;
run;
%mend;
%test(4)
%test(6)