Date: Thu, 24 Aug 2006 10:44:25 -0400
Reply-To: "Dorfman, Paul" <paul_dorfman@MERCK.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Dorfman, Paul" <paul_dorfman@MERCK.COM>
Subject: Re: Fill in missing score
Content-Type: text/plain
Thien,
The fine solutions by Ken and Toby have the advantage of reading the file
once. A more generic solution would read it twice but would also be
impervious to the situation where a non-missing score would happen to be
located not necessarily in the fist record of each ID by-group:
data a ;
input id score ;
cards ;
1 11
1 .
2 .
2 22
2 .
3 .
3 33
;
run ;
data b ;
merge a (drop = score) a (where = (score is not null)) ;
by id ;
run ;
Alternatively (for a Nothin'-But-SQL ),
proc sql ;
create table c as
select x.id, y.score
from a x, a y
where x.id = y.id and y.score is not null
;
quit ;
Of course, if a non-missing score is in the middle of a by-group, you can
still use the DoW-loop, only the file will still have to be read twice:
data d ;
do _n_ = 1 by 1 until (last.id) ;
set a ;
by id ;
if not missing (score) then _iorc_ = score ;
end ;
score = _iorc_ ;
do _n_ = 1 to _n_ ;
set a (drop = score) ;
output ;
end ;
run ;
Kind regards
------------
Paul Dorfman
Jax, FL
------------
+-----Original Message-----
+From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On
+Behalf Of Thien Thai
+Sent: Thursday, August 24, 2006 8:46 AM
+To: SAS-L@LISTSERV.UGA.EDU
+Subject: Fill in missing score
+
+
+Hello, I'm a new SAS user and stumbled across this problem
+where I need to
+fill in the missing score for id that are the same. The data
+set looks like this
+
+ID Score
+12225 0.365516711
+12225
+13073 0.32885697
+13073
+13073
+15494 0.466036457
+15494
+33501 0.159729592
+33501
+
+and basically I would like to have the same score assign to ID
+that are the
+same, any help would be much appreciated.
+
+Ta
+
+Thien
+
+
------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station,
New Jersey, USA 08889), and/or its affiliates (which may be known
outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD
and in Japan, as Banyu - direct contact information for affiliates is
available at http://www.merck.com/contact/contacts.html) that may be
confidential, proprietary copyrighted and/or legally privileged. It is
intended solely for the use of the individual or entity named on this
message. If you are not the intended recipient, and have received this
message in error, please notify us immediately by reply e-mail and then
delete it from your system.
------------------------------------------------------------------------------
|