* Get all combinations of 3 numbers out of 9. * Raynald Levesque 2000/11/24. SET MPRINT=yes. DATA LIST FREE /nbers. BEGIN DATA 1 END DATA. LIST. * This macro finds all combinations of 3 numbers out of n (where n > 3). *////////////////////////////////. DEFINE !doit (!POS=!CMDEND) !LET !x=!NULL STRING answer1 TO answer3 (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 + 1 TO !lastv2. COMPUTE answer2=vec(#cnt2). LOOP #cnt3=#cnt2 + 1 TO !lastv3. COMPUTE answer3=vec(#cnt3). COMPUTE answer=NUMBER(CONCAT(RTRIM(answer1),RTRIM(answer2),RTRIM(answer3)),F8.0). XSAVE OUTFILE='c:\temp\temp.sav' /KEEP=answer. END LOOP. END LOOP. END LOOP. EXECUTE. GET FILE='c:\temp\temp.sav'. FORMATS answer (F8.0). !ENDDEFINE. *////////////////////////////////. !doit 18 5 95 11 8 76 14 4 79. **************@@@@@@@@@ Alternative method. * (unknown author). new file. input program. loop #i1=1 to 9-2. loop #i2=#i1+1 to 9-1. loop #i3=#i2+1 to 9. compute v1=#i1. compute v2=#i2. compute v3=#i3. leave v1 v2. end case. end loop. end loop. end loop. end file. end input program. execute. recode v1,v2,v3 (1=18)(2=5)(3=95)(4=11)(5=8)(6=76)(7=14)(8=4)(9=79). compute answer=number(concat(ltrim(string(v1,F8.0)),ltrim(string(v2,F8.0)),ltrim(string(v3,F8.0))),F8.0). execute. formats answer (F8.0).