LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 1998, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 5 Jun 1998 08:35:00 +0200
Reply-To:   "Becker, Eckhard [IAW-04]" <EBecker@VHV.DE>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   "Becker, Eckhard [IAW-04]" <EBecker@VHV.DE>
Subject:   Re: Word jumble problem: How to get all possible combinations?
Content-Type:   text/plain

Jingren,

you're right, your code is faster but it's wrong :-( E.g. the last loop in your code will generate 'EEEEE', and this is not wanted. You get the same number of obs, so something is missing: All your word's are 'sorted': The first letter is le the second and so on. E.g. the desired value 'ECDAB' is miisng in your output. Eckhard >Your code has excellent ideas. However, if it could be changed a little, it >will be more efficient. > >The doloop will be 5*4*3*2*1 instead of 5*5*5*5*5 plus a if-then with your >looping. > >PROC format; > VALUE letter 1='a' > 2='b' > 3='c' > 4='d' > 5='e'; >RUN; > >DATA str5; > LENGTH word $5 c1 c2 c3 c4 c5 $1; > DO n1=1 to 5; > DO n2=2 to 5; > DO n3=3 to 5; > DO n4=4 to 5; > DO n5=5 to 5; > c1=PUT(n1,letter.); > c2=PUT(n2,letter.); > c3=PUT(n3,letter.); > c4=PUT(n4,letter.); > c5=PUT(n5,letter.); > word=c1!!c2!!c3!!c4!!c5; > OUTPUT; > END; > END; > END; > END; > END; >RUN; > >>>It generates a dataset with 120 unique combinations of the letters a,b,c,d >>>and e. >>> >>>PROC format; >>> VALUE letter 1='a' >>> 2='b' >>> 3='c' >>> 4='d' >>> 5='e'; >>>RUN; >>> >>>DATA str5; >>> LENGTH word $5 c1 c2 c3 c4 c5 $1; >>> DO n1=1 to 5; >>> DO n2=1 to 5; >>> DO n3=1 to 5; >>> DO n4=1 to 5; >>> DO n5=1 to 5; >>> c1=PUT(n1,letter.); >>> c2=PUT(n2,letter.); >>> c3=PUT(n3,letter.); >>> c4=PUT(n4,letter.); >>> c5=PUT(n5,letter.); >>> word=c1!!c2!!c3!!c4!!c5; >>> IF INDEX(word,'a')>0 AND >>> INDEX(word,'b')>0 AND >>> INDEX(word,'c')>0 AND >>> INDEX(word,'d')>0 AND >>> INDEX(word,'e')>0 THEN OUTPUT; >>> END; >>> END; >>> END; >>> END; >>> END; >>>RUN;


Back to: Top of message | Previous page | Main SAS-L page