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 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 7 Dec 2006 10:26:16 -0500
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject:      Re: sorting problem

On Thu, 7 Dec 2006 06:53:58 -0800, Mogens A. Krogh <MKROGH@DSR.KVL.DK> wrote:

>Sorry! >The multipurpose tool "the colon-delimiter" doesn't work with the >retain statement.

Sure it does.

data _null_; set sashelp.class(keep=name obs=3); retain n : ; if _n_=1 then newvar = 99; put newvar= ; run;

gives us

newvar=99 newvar=. newvar=.

only because when the compiler sees the RETAIN statement NEWVAR is not yet in the PDV.

Just change the order to

data _null_; set sashelp.class(keep=name obs=3); if _n_=1 then newvar = 99; put newvar= ; retain n : ; run;

and the result becomes

newvar=99 newvar=99 newvar=99

> >The right code is below (and very equal to Dan Nordlunds sugestion). > >Regards >Mogens > >data want; >set test; >by id; >retain _score1 _score2; >if first.id then do; >_score1=.;_score2=.; >end; >if score1>_score1 then _score1=score1; >if score2>_score2 then _score2=score2; >if last.id then output; >drop score:; >run; > > > > >Mogens A. Krogh skrev: >> Dear Gopi, >> You could do something like this. >> >> data test; >> input id score1 score2; >> cards; >> 1 10 11 >> 1 10 20 >> 2 18 17 >> 3 11 13 >> 3 12 13 >> 4 10 19 >> 5 17 20 >> 5 21 20 >> ; >> run; >> data want; >> set test; >> by id; >> retain _score:; >> if first.id then do; >> _score1=.;_score2=.; >> end; >> if score1>_score1 then _score1=score1; >> if score2>_score2 then _score2=score2; >> if last.id then output; >> drop score:; >> run; >> >> Regards >> Mogens A. Krogh >> DVM, PhD-student >> www.kvl.dk >> gopilth@yahoo.com skrev: >> > Hi, >> > I have a problem sorting data sets >> > data set A: >> > id score1 score2 >> > 1 10 11 >> > 1 10 20 >> > 2 18 17 >> > 3 11 13 >> > 3 12 13 >> > 4 10 19 >> > 5 17 20 >> > 5 21 20 >> > >> > out put file: >> > id score1 score2 >> > 1 10 20 >> > 2 18 17 >> > 3 12 13 >> > 4 10 19 >> > 5 21 20 >> > >> > output should not have repeates of id's and should have highest score >> > (both in score1 and score2). >> > thanks in advance >> > gopi.


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