* Get all combinations (with replacement) of 3 letters out of N. * Raynald Levesque 2002/06/2. SET MPRINT=yes. DATA LIST FREE /nbers. BEGIN DATA 1 END DATA. LIST. * This macro finds all combinations (with replacement) of 3 letters out of n (where n > 3). *////////////////////////////////. DEFINE !doit (!POS=!CMDEND) !LET !x=!NULL STRING answer1 TO answer3 answer (A8). !DO !var !IN (!1) !LET !x=!CONCAT(!x,!BLANKS(1)) STRING !CONCAT('V',!LENGTH(!x)) (A8). COMPUTE !CONCAT('V',!LENGTH(!x))=!QUOTE(!var). !DOEND !LET !lastv1=!LENGTH(!SUBSTR(!x,3)) !LET !lastv2=!LENGTH(!SUBSTR(!x,2)) !LET !lastv3=!LENGTH(!SUBSTR(!x,1)) VECTOR vec=v1 TO !CONCAT('V',!LENGTH(!x)). LOOP #cnt1=1 TO !lastv1. COMPUTE answer1=vec(#cnt1). LOOP #cnt2=#cnt1 TO !lastv2. COMPUTE answer2=vec(#cnt2). LOOP #cnt3=#cnt2 TO !lastv3. COMPUTE answer3=vec(#cnt3). COMPUTE answer=CONCAT(RTRIM(answer1),RTRIM(answer2),RTRIM(answer3)). XSAVE OUTFILE='c:\\temp\\temp.sav' /KEEP=answer. END LOOP. END LOOP. END LOOP. EXECUTE. GET FILE='c:\\temp\\temp.sav'. !ENDDEFINE. *////////////////////////////////. !doit A B C G K L P S T V X Y.