From: Richard A. DeVenezia on 11 Nov 2009 12:18 On Nov 11, 3:43 am, Fernández Rodríguez, Dani wrote: > Hi, > > I have improved the code for your transposed pairs. > > Here the complete code: .... > > %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; ..... Where is Toby when you need him ? Macro is a great tool but you should consider its use carefully. Toby would say should never use it if there is a effective non-macro way, with the caveat that there is almost always such a way. Here is sample code for a pair tabulator that utilizes a reflexive join performed in SQL. As shown, the technique is easily extended to triples and would be very efficient for implementing business-rule selection criteria if there were any. ----------------- data have; 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; * a transpose view; data haveT / view=haveT; set have; rowid = _n_; array col col1-col10; do index = 1 to dim(col); value = col(index); OUTPUT; end; keep rowid index value; run; proc sql; create table pairs as select A.rowid , catx('-',A.value,B.value) as pair length=10 from haveT as A , haveT as B where A.rowid = B.rowid & A.index < B.index order by A.rowid, A.index, B.index ; quit; proc sql; create table triples as select A.rowid , catx('-',A.value,B.value,C.value) as triple length=10 from haveT as A , haveT as B , haveT as C where A.rowid = B.rowid & B.rowid = C.rowid & A.index < B.index & B.index < C.index order by A.rowid, A.index, B.index, C.index ; quit; ----------------- Richard A. DeVenezia http://www.devenezia.com
First
|
Prev
|
Pages: 1 2 Prev: Comparing SSNs - how different are they? Next: Zero-inflated Poisson for correlated data |