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 (August 2000, 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 Aug 2000 17:17:02 EDT
Reply-To:     Bernard Tremblay <imaginasys@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Bernard Tremblay <imaginasys@HOTMAIL.COM>
Subject:      Re: Sorting it all out
Comments: To: lboltzmann@mail.nu
Content-Type: text/plain; charset=iso-8859-1; format=flowed

Hi Ludwig,

Lets say that each group of variables are a "group". To sort this out you have to output one variable for each group, and then sort by group and variable. After that you replace observation as they where with all the groups into one observation.

I tested the following code on MVS and SAS V8 : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /*** Build test data for two observations ***/ data; input @1 a1-a10 2.; input @1 b1-b10 2.; input @1 c1-c10 2.; input @1 d1-d10 2.; input @1 e1-e10 2.; cards; 9 9 9 9 9 1 1 1 1 1 1 1 1 3 3 4 4 5 5 5 7 2 7 8 9 1 0 6 3 5 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 8 8 8 8 8 2 2 2 2 2 2 2 2 4 4 5 5 6 6 6 6 1 6 7 8 0 9 5 2 4 9 0 1 2 3 4 5 6 7 8 9 8 6 5 4 3 2 1 0 9 ;;;; run; /*** Let*s change file format for the sort ***/ data forsort(keep=obsid type val)/debug /**/; set; format type $1. val 16.; array m{5,10} a1-a10 b1-b10 c1-c10 d1-d10 e1-e10; obsid=_n_; do i=1 to 5; type=substr('ABCDE',I,1); do j=1 to 10; val=m{i,j}; output; end; end; run; /*** Proceed to sort ***/ proc sort; by obsid type val;run; /**** Put back everything like it was ***/ data sorted(keep=a1-a10 b1-b10 c1-c10 d1-d10 e1-e10); set forsort; by obsid type val; array m{50} a1-a10 b1-b10 c1-c10 d1-d10 e1-e10; retain i m; if first.obsid then do; do i=1 to 50; m{i}=.; end; i=0; end; i+1; m{i}=val; if last.obsid then output; run; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ As you see the method can work for many observations. The key is to bring the file format such a way that we can sort it with a regular sort.

But I'm sure others sas-l'ers will find some other interesting ways to do the task!

I hope it helps, \\\|/// \\ - - // ( @ @ ) +-----oOOo-(_)-oOOo--+-----------------------------------+ | Bernard Tremblay | | | CSST | Tel: (418) 528-9313 | | | Fax: (418) 528-1493 | | | Int: Bernard.Tremblay@csst.qc.ca | +----------------------------+---------------------------+ | Imaginasys enr | Res: (418) 658-1411 | | | Int: bertrem@videotron.ca | | | Hot: imaginasys@hotmail.com | +--------------Oooo--+-----------------------------------+ oooO ( ) ( ) ) / \ ( (_/ \_) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >From: ludwig boltzmann <lboltzmann@MAIL.NU> >Reply-To: lboltzmann@mail.nu >To: SAS-L@LISTSERV.UGA.EDU >Subject: Sorting it all out >Date: Thu, 17 Aug 2000 12:42:24 -0700 > >Hello sas-l: > >I can't figure out how to sort this out (literally). I have a sas dataset >with 10 variable lists a1-a10, b1-b10, ... j1-j10. E.g. in one observation >they may look like this: > >a1-a10: 9 9 9 9 9 1 1 1 1 1 >b1-b10: 1 1 1 3 3 4 4 5 5 5 >c1-c10: 7 2 7 8 9 1 0 6 3 5 >d1-d10: 0 1 2 3 4 5 6 7 8 9 >e1-e10: 0 1 2 3 4 5 6 7 8 9 > >I'm only showing 5 1-digit lists for simplicity (the actual numbers have up >to 16 digit). What I need is to order the whole thing *in every >observation* by ascending a, descending b, ascending c, as if each >occurrence of the lists (i.e. a1,b1,c1...) was a record. The rest of the >lists (tails) must be transposed in sync. For instance the sample >observation just shown would turn into this: > >a1-a10: 1 1 1 1 1 9 9 9 9 9 >b1-b10: 5 5 5 4 4 3 3 1 1 1 >c1-c10: 3 5 6 0 1 8 9 2 7 7 >d1-d10: 8 9 7 6 5 3 4 1 0 2 >e1-e10: 8 9 7 6 5 3 4 1 0 2 > >I'm failing to figure out how to use proc sort in this setting. Any ideas, >suggestions, etc. are highly valued and deeply appreciated. Ludwig > > > >_____________________________________________________________ >Get Your Own .NU Web Address Now! ---> http://WWW.NUNAMES.NU ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com


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