```Date: Fri, 5 Jun 1998 00:34:41 GMT Reply-To: jshi@KUHUB.CC.UKANS.EDU Sender: "SAS(r) Discussion" From: Jingren Shi Organization: Deja News - The Leader in Internet Discussion Subject: Re: Word jumble problem: How to get all possible combinations? At 09:16 AM 6/4/98 -0700, you wrote: Anneke, 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. Good luck! Jingren 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; >Very slick, thanks. > >At 03:46 PM 6/4/98 +0200, Anneke de Win wrote: >>Hello, >> >>Would this be of any help? >>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; >> >>Greetings, Anneke >> >> >> >>>Having recently stumbled across some word Jumble problems, I've decided to >>>take a stab at programming a solution to the "all possible combintations" >>>algorithm in SAS. I've got some Data Step code working, but it seems >>>really inefficient and ugly. >>>All I want to do is generate all possible combinations for a string of >>>characters. Hence, the string "ABC" yields 6 strings: >>> >>> abc acb bac bca cab cba >>> >>>and "ABCD" generates 24 strings, and so on. This is basically a factorial >>>problem, right? I must be missing something, but I have yet to find a >>>simple SAS solution... >>> >>>Thanks for any ideas! >>> >>>Jim Carter >>> >> >> >/******************************************/ >William W. Viergever >Viergever & Associates >A SAS Institute Quality Partner in the USA >Sacramento, CA >V: (916) 483-8398 >F: (916) 486-1488 >wwvierg@ibm.net >/******************************************/ -----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/ Now offering spam-free web-based newsreading ```

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