From: Fernández Rodríguez, on 10 Nov 2009 10:27 Hi Marianne, It is simpler than it seems: DATA NEED; set temp; new_variable=catx(',', catx('-',col1,col2), catx('-',col3,col4), catx('-',col5,col6), catx('-',col7,col8), catx('-',col9,col10)); run; Daniel Fernandez Barcelona -----Mensaje original----- De: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] En nombre de Marianne Kang Enviado el: dimarts, 10 / novembre / 2009 16:21 Para: SAS-L(a)LISTSERV.UGA.EDU Asunto: combinations problem Hi,evevyone, Does someone can help me to solve this problem? I'm trying to use the loops, but not succeed... data temp; input col1 $ col2 $ col3 $ col4 $ col5 $ col6 $ col7 $ col8 $ col9 $ col10 $ ; cards; 1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z d d c d ; run; want to produce a new variable containing various combination of col1 to col10 such as for the first record, I need have 1-2, 1-3, ...,1-10, 2-3, 2-4, ...,2-10, 3-4, 3-4,...,3-10,....,9-10, a-b, a-c,...,a-j,b-c,......c-d(last one) stored in a new variable. Thank you so much for your help. Marianne
From: Fernández Rodríguez, on 10 Nov 2009 10:30 Ops!!! :( I am just watching it has more combinations than I saw at first! Dani -----Mensaje original----- De: Fern�ndez Rodr�guez, Dani Enviado el: dimarts, 10 / novembre / 2009 16:28 Para: 'Marianne Kang'; SAS-L(a)LISTSERV.UGA.EDU Asunto: RE: combinations problem Hi Marianne, It is simpler than it seems: DATA NEED; set temp; new_variable=catx(',', catx('-',col1,col2), catx('-',col3,col4), catx('-',col5,col6), catx('-',col7,col8), catx('-',col9,col10)); run; Daniel Fernandez Barcelona -----Mensaje original----- De: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] En nombre de Marianne Kang Enviado el: dimarts, 10 / novembre / 2009 16:21 Para: SAS-L(a)LISTSERV.UGA.EDU Asunto: combinations problem Hi,evevyone, Does someone can help me to solve this problem? I'm trying to use the loops, but not succeed... data temp; input col1 $ col2 $ col3 $ col4 $ col5 $ col6 $ col7 $ col8 $ col9 $ col10 $ ; cards; 1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z d d c d ; run; want to produce a new variable containing various combination of col1 to col10 such as for the first record, I need have 1-2, 1-3, ...,1-10, 2-3, 2-4, ...,2-10, 3-4, 3-4,...,3-10,....,9-10, a-b, a-c,...,a-j,b-c,......c-d(last one) stored in a new variable. Thank you so much for your help. Marianne
From: Richard A. DeVenezia on 10 Nov 2009 11:30 On Nov 10, 10:20 am, tongjunk...(a)HOTMAIL.COM (Marianne Kang) wrote: > Hi,evevyone, > Does someone can help me to solve this problem? I'm trying to use the > loops, but not succeed... > > data temp; > input col1 $ col2 $ col3 $ col4 $ col5 $ col6 $ col7 $ col8 $ col9 $ col10 > $ ; > cards; > 1 2 3 4 5 6 7 8 9 0 > a b c d e f g h i j > k l m n o p q r s t > u v w x y z d d c d > ; > run; > want to produce a new variable containing various combination of col1 to > col10 > such as for the first record, I need have > 1-2, 1-3, ...,1-10, 2-3, 2-4, ...,2-10, 3-4, 3-4,...,3-10,....,9-10, a-b, > a-c,...,a-j,b-c,......c-d(last one) stored in a new variable. > > Thank you so much for your help. > Marianne Marianne: 10 items taken 2 at a time will result in COMB(10,2) pairs, which is 45. I'm not sure where your a-b values come from in your 'need have'. I'm not sure what you mean when you say various combinations. What do you want to do with each pair ? - A math operation ? - A string concatentation ? - Do you really want the enumerated pair list in a single variable ? <--- SAMPLE In the sample code the COMB function and CALL routine ALLCOMB are used to iterate over the pairs constructed from the items in an array. If your version of SAS does not have ALLCOMB (9.2 does) there are work arounds that involve more coding. --------------------- data have; retain id 1; array x x1-x10 (1:10); output; id+1; do over x; x+100; end; output; run; data want(keep=id x1-x10 pairlist); set have; array x x1-x10; length pairlist $500; do _n_ = 1 to comb(dim(x),2); call allcomb (_n_, 2, of x(*)); pair = catx(':',x(1),x(2)); pairlist = catx(', ',pairlist,pair); end; run; --------------------- Richard A. DeVenezia http://www.devenezia.com
From: Fernández Rodríguez, on 10 Nov 2009 11:01 I think you will enjoy this other one: d%macro colas; %do y=1 %to 9; %do n=%eval(&y+1) %to 10; %put &n; _text&y&n= catx('-',col&y,col&n); %end; %end; %mend; data need; length new_variable $300.; set temp; %colas; new_variable=catx(',',of _text: ); drop _text:; put new_variable; run; Daniel Fernandez Barcelona -----Mensaje original----- De: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] En nombre de Marianne Kang Enviado el: dimarts, 10 / novembre / 2009 16:21 Para: SAS-L(a)LISTSERV.UGA.EDU Asunto: combinations problem Hi,evevyone, Does someone can help me to solve this problem? I'm trying to use the loops, but not succeed... data temp; input col1 $ col2 $ col3 $ col4 $ col5 $ col6 $ col7 $ col8 $ col9 $ col10 $ ; cards; 1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z d d c d ; run; want to produce a new variable containing various combination of col1 to col10 such as for the first record, I need have 1-2, 1-3, ...,1-10, 2-3, 2-4, ...,2-10, 3-4, 3-4,...,3-10,....,9-10, a-b, a-c,...,a-j,b-c,......c-d(last one) stored in a new variable. Thank you so much for your help. Marianne
From: Fernández Rodríguez, on 11 Nov 2009 03:43 Hi, I have improved the code for your transposed pairs. Here the complete code: =20 data temp; input col1 $ col2 $ col3 $ col4 $ col5 $ col6 $ col7 $ col8 $ col9 $ = col10 $ ; cards; 1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z d d c d ; run; =20 %macro colas; %do y=3D1 %to 9; %do n=3D%eval(&y+1) %to 10; %put &n; _text&y&n=3D catx('-',col&y,col&n); %end; %end; %mend; =20 data need; length new_variable $300.; set temp; %colas; new_variable=3Dcatx(',',of _text: ); drop _text:; run; =20 data need; set need; array pair(45)$ pair1-pair45; do y=3D1 to 45; pair(y)=3Dscan(new_variable,y,','); end; drop y col:; run; proc transpose data=3Dneed out=3Dunique_pairs prefix=3DLINE; var pair:; run; =20 *IF YOU WANT ONLY ONE COLUMN WITH ALL PAIRS, EXECUTE THIS:; data unique_pairs_1column; set unique_pairs (keep=3Dline1 rename=3Dline1=3Dpair) unique_pairs (keep=3Dline2 rename=3Dline2=3Dpair) unique_pairs (keep=3Dline3 rename=3Dline3=3Dpair) unique_pairs (keep=3Dline4 rename=3Dline4=3Dpair) ; run; =20 =20 Daniel Fernandez Barcelona =20 =20 ________________________________ De: tongjun kang [mailto:tongjunkang(a)hotmail.com]=20 Enviado el: dimarts, 10 / novembre / 2009 17:18 Para: Fern=E1ndez Rodr=EDguez, Dani; sas-l(a)listserv.uga.edu Asunto: SUSPECT: RE: combinations problem =20 Looks so neat. But can I ask something more? I need to store 1-2 or 3-4 = individually (vertically as two observation) in New_variable, not the = 1-2,1-3.... concatenated as one record. I'm sorry that I missled you in = my question. Is it possible to do that? =20 > Date: Tue, 10 Nov 2009 17:01:25 +0100 > From: DFernandez(a)CST.CAT > Subject: Re: combinations problem > To: SAS-L(a)LISTSERV.UGA.EDU >=20 > I think you will enjoy this other one: >=20 > d%macro colas; > %do y=3D1 %to 9; > %do n=3D%eval(&y+1) %to 10; > %put &n; > _text&y&n=3D catx('-',col&y,col&n); > %end; > %end; > %mend; >=20 > data need; > length new_variable $300.; > set temp; > %colas; > new_variable=3Dcatx(',',of _text: ); > drop _text:; > put new_variable; > run; >=20 >=20 > Daniel Fernandez > Barcelona >=20 >=20 >=20 >=20 >=20 > -----Mensaje original----- > De: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] En nombre de = Marianne Kang > Enviado el: dimarts, 10 / novembre / 2009 16:21 > Para: SAS-L(a)LISTSERV.UGA.EDU > Asunto: combinations problem >=20 > Hi,evevyone, > Does someone can help me to solve this problem? I'm trying to use the > loops, but not succeed... >=20 > data temp; > input col1 $ col2 $ col3 $ col4 $ col5 $ col6 $ col7 $ col8 $ col9 $ = col10 > $ ; > cards; > 1 2 3 4 5 6 7 8 9 0 > a b c d e f g h i j > k l m n o p q r s t > u v w x y z d d c d > ; > run; > want to produce a new variable containing various combination of col1 = to > col10 > such as for the first record, I need have > 1-2, 1-3, ...,1-10, 2-3, 2-4, ...,2-10, 3-4, 3-4,...,3-10,....,9-10, = a-b, > a-c,...,a-j,b-c,......c-d(last one) stored in a new variable. >=20 > Thank you so much for your help. > Marianne ________________________________ Find the right PC with Windows 7 and Windows Live. Learn more. = <http://www.microsoft.com/Windows/pc-scout/laptop-set-criteria.aspx?cbid=3D= wl&filt=3D200,2400,10,19,1,3,1,7,50,650,2,12,0,1000&cat=3D1,2,3,4,5,6&bra= nds=3D5,6,7,8,9,10,11,12,13,14,15,16&addf=3D4,5,9&ocid=3DPID24727::T:WLMT= AGL:ON:WL:en-US:WWL_WIN_evergreen2:112009>=20
|
Next
|
Last
Pages: 1 2 Prev: Comparing SSNs - how different are they? Next: Zero-inflated Poisson for correlated data |