Date: Mon, 7 Jul 2003 09:43:47 -0700
Reply-To: "Huang, Ya" <yhuang@AMYLIN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Huang, Ya" <yhuang@AMYLIN.COM>
Subject: Re: Selecting Obs.
Content-Type: text/plain; charset="iso-8859-1"
How about sql?
DATA clinic;
INPUT subid 3. l_intake
ddmmyy10. visit_dt ddmmyy10.;
FORMAT l_intake visit_dt date9.;
CARDS;
001 01062003 12062003
001 01062003 14062003
001 01062003 20062003
002 01052003 09052003
002 01052003 16052003
003 05052003 13052003
;
RUN;
proc sql;
select *
from clinic
group by subid
having abs(l_intake+13-visit_dt)=min(abs(l_intake+13-visit_dt))
;
-------------------
subid l_intake visit_dt
ffffffffffffffffffffffffffffff
1 01JUN2003 14JUN2003
2 01MAY2003 16MAY2003
3 05MAY2003 13MAY2003
If there is a tie, it will pick up both of them,
if you can define a rule for breaking up the tie,
I may try to add something in the code.
Kind regards,
Ya Huang
-----Original Message-----
From: Franz [mailto:franz_cl2003@YAHOO.FR]
Sent: Monday, July 07, 2003 9:27 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Selecting Obs.
Dear all,
I have the following situation:
DATA clinic;
INPUT subid 3. l_intake
ddmmyy10. visit_dt ddmmyy10.;
FORMAT l_intake visit_dt date9.;
CARDS;
001 01062003 12062003
001 01062003 14062003
001 01062003 20062003
002 01052003 09052003
002 01052003 16052003
003 05052003 13052003
;
RUN;
Out of the previous dataset (clinic) I would like
to select only one observation per subid according
to the following conditions:
* If the the patient have only one observation then
this Observation must be selected.
* If he has more than one observation (the case
with subid 001 and 002) then I must select the
observation where the visit date (visit_dt) is
much closer to the last intake date +14
(l_intake +14)
This means, my final dataset should only have these
3 observations.
001 01062003 14062003
002 01052003 16052003
003 05052003 13052003
Thank you very much!
Regards,
Franz.
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com