Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!psuvax1!psuvm!SASK!BICKIS From: BICKIS@SASK.USASK.CA (Mikelis Bickis) Newsgroups: bit.listserv.sas-l Subject: SAS code for generating permutations Message-ID: Date: 11 Jan 90 22:59:00 GMT Sender: "SAS(r) Discussion" Reply-To: Mikelis Bickis Lines: 42 Approved: NETNEWS@PSUVM Gateway X-VMS-To: IN::"HAMER@VCUVAX.BITNET",IN::"SAS-L@UALTAVM.BITNET" Comments: To: HAMER@VCUVAX.BITNET /* Here is some SAS code to generate a dataset containing all the permutations of the integers 1 to n. Before invoking the code you must %LET n= the number you want, and if you want to give the dataset a name, you may %LET FILE= the name you want. This really should be written up as a bona fide macro, but our version of SAS doesn't seem to have the full SAS MACRO capability---but that is another issue. Mik Bickis Dept. of Mathematics University of Saskatchewan Saskatoon BICKIS@SASK.BITNET bickis@sask.usask.ca <( I use SAS 5.18 running on a VAX 6300 cluster under VMS 5.1 )> */ DATA &FILE; ARRAY NUMBERS {*} I1-I&n; ARRAY TALLIES {*} T1-T&n; KEEP I1-I&n; /* Generate list of integers in normal order */ DO J=1 TO &n; NUMBERS{J}=J; END; OUTPUT; MIX=1; DO WHILE(MIX<&n); /* cyclically permute first MIX+1 numbers */ HOLD=NUMBERS{1}; DO J=1 TO MIX; NUMBERS{J}=NUMBERS{J+1}; END; NUMBERS{MIX+1}=HOLD; TALLIES{MIX}+1; IF TALLIES{MIX}