```Date: Wed, 16 Aug 2006 13:53:40 -0400 Reply-To: "Howard Schreier " Sender: "SAS(r) Discussion" From: "Howard Schreier " Subject: Re: Coding Combinations question On Wed, 16 Aug 2006 16:59:02 +0000, toby dunn wrote: >Machelle , > >Data Have ; >Infile Cards ; >Input ID Drug1 Drug2 Drug3 Drug4 Drug5 Drug6 Drug7 Drug8 ; >Cards ; >1 2 0 0 0 0 0 0 0 >2 0 1 3 0 0 0 0 0 >3 0 0 0 0 1 1 1 0 >4 1 0 0 0 0 0 0 0 >; >Run ; > >Data Need ( Drop = I ) ; >Length Combination \$45 ; >Set Have ; >Array Drug (*) Drug: ; > >Do I = 1 to Dim( Drug ) ; > If ( Drug(I) > 0 ) Then Combination = Cats( Combination , Vname( Drug(I) ) >) ; >End ; > >Run ; I would probably do it Toby's way, but here's an alternative: proc transpose data=have out=long(where=(col1) ); by id; run; proc transpose data=long out=wide; by id; var _name_; run; data need(keep = id combination); set wide; combination = cats(of drug : ); run; > > >Proc Print >Data = Need ; >Run ; > > > > >Toby Dunn > >Normal People Worry Me!!!!! > >I reject your reality and substitute my own!!! > > > > > >From: machelle >Reply-To: machelle >To: SAS-L@LISTSERV.UGA.EDU >Subject: Coding Combinations question >Date: Wed, 16 Aug 2006 09:38:36 -0700 > >Hi >I've looked up previous questions about permutations and combinations, >but I think my question is different... > >I have 8 different drug types per patient and I want to create a >variable that looks at all the possible combinations of these 8 drug >types: > >ID Drug1 Drug2 Drug3 Drug4 Drug5 Drug6 Drug7 Drug8 >1 2 0 0 0 0 0 0 0 > >2 0 1 3 0 0 0 0 0 > >3 0 0 0 0 1 1 1 0 > >4 1 0 0 0 0 0 0 0 > > >What I want is a variable called "combination": > >ID Drug1 Drug2 Drug3 Drug4 Drug5 Drug6 Drug7 Drug8 Combination >1 2 0 0 0 0 0 0 0 > Drug1 >2 0 1 3 0 0 0 0 0 > Drug2Drug3 >3 0 0 0 0 1 1 1 0 > Drug5Drug6Drug6 >4 1 0 0 0 0 0 0 0 > Drug1 > >I've looked at Proc PLan for the past half hour but I'm not convinced >that this is what will do the trick. > >Any Ideas? > >Thanks, > >Machelle ```

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