Date: Thu, 7 Dec 2006 11:00:30 -0500
Reply-To: Nathaniel_Wooding@DOM.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Nat Wooding <Nathaniel_Wooding@DOM.COM>
Subject: Re: sorting problem
In-Reply-To: <200612071526.kB7BkIBc014879@mailgw.cc.uga.edu>
Content-Type: text/plain; charset="US-ASCII"
A small addendum to this tread:
I had not realized it until I looked at this code but the trailing colon
operator does not have to end the string but rather simply needs to follow
it.
Moreover, while doing a little playing, I may have stumbled on a small bug.
Consider the following code:
data a;
set sashelp.class(keep=name obs=3);
if _n_=1 then do;
newvar = 99;
xvar= 191;
end;
retain a b : 22 ;
proc print;
run;
Now, as I count variables, there should be 5 in the output data set: name,
newvar,xvar, a and b. However, when I run this on WinXP, 9.1, I get only 4
-- there is no variable called "b".
The log reads:
NOTE: There were 3 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.A has 3 observations and 4 variables
I think a call to Cary is in order.
Nat Wooding
"Howard Schreier
<hs AT dc-sug DOT
org>" To
Sent by: "SAS(r) SAS-L@LISTSERV.UGA.EDU
Discussion" cc
<SAS-L@LISTSERV.U
GA.EDU> Subject
Re: sorting problem
12/07/2006 10:26
AM
Please respond to
"Howard Schreier
<hs AT dc-sug DOT
org>"
<nospam@HOWLES.CO
M>
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.
-----------------------------------------
CONFIDENTIALITY NOTICE: This electronic message contains
information which may be legally confidential and/or privileged and
does not in any case represent a firm ENERGY COMMODITY bid or offer
relating thereto which binds the sender without an additional
express written confirmation to that effect. The information is
intended solely for the individual or entity named above and access
by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying, distribution, or use of the
contents of this information is prohibited and may be unlawful. If
you have received this electronic transmission in error, please
reply immediately to the sender that you have received the message
in error, and delete it. Thank you.