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 (December 2009, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 17 Dec 2009 14:53:43 -0800
Reply-To:     Tom Abernathy <tom.abernathy@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Tom Abernathy <tom.abernathy@GMAIL.COM>
Organization: http://groups.google.com
Subject:      Re: Transpose function?
Comments: To: sas-l@uga.edu
Content-Type: text/plain; charset=ISO-8859-1

Not sure what exactly is your problem is with the date variables? Are you saying that DATE1 is character and DATE2 is numeric? If that is the case then array will not work. If instead it is finde DATEMY which is character and trying to use it in the _date array then you can fix that by changine the variable list in the array statement from variables that start with date (date:) to the actual list of variables you want (date1-date10) then it will work.

- Tom Abernathy

On Dec 17, 3:13 pm, Sdlentertd <sdlente...@gmail.com> wrote: > On Dec 17, 1:06 pm, "Richard A. DeVenezia" <rdevene...@gmail.com> > wrote: > > > > > > > On Dec 17, 2:06 pm, Sdlentertd <sdlente...@gmail.com> wrote: > > > > I have a SAS dataset with these columns: > > > loc1 member1 rx1 date1 loc2 member2 rx2 date2 > > > NY M025 0545 01SEP2009 MN J545 0689 05SEP2009 > > > TN N123 0145 02SEP2009 AR J654 1234 06SEP2009 > > > > I need to put all those columns into rows and the main columns will be > > > Loc Member rx date > > > NY M025 0545 01SEP2009 > > > TN J545 0689 05SEP2009 > > > MN N123 0145 02SEP2009 > > > AR J654 1234 06SEP2009 > > > > I am looking to transpose those columns into rows; and the values > > > would match appropriate columns > > > > There are like 50 original columns and all of them have 1 through 10 > > > at the end of the variable name . > > > Thank you > > > There are two common ways to transpose information in a table > > - Proc TRANSPOSE > > - DATA Step and Arrays > > Some uncommon ways would include > > - DATA Step and Hash object > > > Since your original data does not appear to already have categorical > > variables for grouping, the array approach might be clear to you. > > > ----------------------- > > data have; > > input > > loc1 $ member1 $ rx1 date1 date9. > > loc2 $ member2 $ rx2 date2 date9. > > ; > > format date1 date2 date9.; > > datalines; > > NY M025 0545 01SEP2009 MN J545 0689 05SEP2009 > > TN N123 0145 02SEP2009 AR J654 1234 06SEP2009 > > run; > > > data need; > > input > > Loc $ Member $ rx date date9. ; > > format date; > > datalines; > > NY M025 0545 01SEP2009 > > TN J545 0689 05SEP2009 > > MN N123 0145 02SEP2009 > > AR J654 1234 06SEP2009 > > run; > > > data want; > > set have; > > array _loc loc:; > > array _member member:; > > array _rx rx:; > > array _date date:; > > rowid + 1; > > do _n_ = 1 to dim(_loc); > > group = _n_; > > loc = _loc(_n_); > > member = _member(_n_); > > rx = _rx(_n_); > > date = _date(_n_); format date date9.; > > OUTPUT; > > end; > > keep loc member rx date rowid group; > > run; > > > proc sort data=want out=want2; > > by group rowid; > > run; > > ----------------------- > > > Also, arrays based approaches are often used when multiple columns are > > to be transposed in parallel. The array way requires one pass, > > whereas an equivalent proc transpose way requires multiple passes and > > a merge. > > > -- > > Richard A. DeVenezia- Hide quoted text - > > > - Show quoted text - > > One problem: My date is in different format Date9. (unlike other > character fields) and it doesn't work in the array with other > variables.- Hide quoted text - > > - Show quoted text -


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