* This macro finds all permutations of the integers 1, 2, ... t where t < 8. * Raynald Levesque Feb. 2002. DEFINE !t(nb=!TOKENS(1)) /* Create a file containing all combinations (with replacements)*/. INPUT PROGRAM. !DO !cnt=1 !TO !nb LOOP !CONCAT('cnt',!cnt,'=1 TO ',!nb). LEAVE !CONCAT('cnt',!cnt). !DOEND END CASE. !DO !cnt=1 !TO !nb. END LOOP. !DOEND END FILE. END INPUT PROGRAM. * Count if some number appears more than once. NUMERIC c1 TO !CONCAT('c',!nb). !DO !cnt=1 !TO !nb COUNT !CONCAT('c',!cnt,' =cnt1 TO c',!cnt,'(',!cnt,')'). !DOEND /* Keep only true permutations (without replacements)*/. SELECT IF MAX(c1 TO !CONCAT('c',!nb))=1. EXECUTE. STRING newname(A8). COMPUTE newname=CONCAT('p',LTRIM(STRING($CASENUM,F8.0))). FLIP cnt1 TO !CONCAT('cnt',!nb) /NEWNAMES=newname. SAVE OUTFILE='c:\\temp\\all permutations.sav' /DROP=case_lbl. !ENDDEFINE. !t nb=6.