Date: Tue, 17 Nov 2009 01:54:39 -0500
Reply-To: Søren Lassen <s.lassen@POST.TELE.DK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Søren Lassen <s.lassen@POST.TELE.DK>
Subject: Re: Comparing Dates From 2 Different Files
Content-Type: text/plain; charset=ISO-8859-1
Here is a datastep solution, which may be quite a lost faster with
realistic amounts of data:
data one;
informat id 3. date mmddyy8.;
input id date;
format date date9.;
cards;
1 01/06/09
1 02/07/09
2 02/01/09
;run;
data two;
informat id 3. date mmddyy8.;
input id date;
format date date9.;
cards;
1 03/07/09
1 04/09/09
1 04/30/09
2 03/06/09
2 07/07/09
;run;
proc sort data=one;
by id descending date;
run;
proc sort data=two;
by id descending date;
run;
data want;
set two(in=in2) one(in=in1);
by id descending date;
format date2 date9.;
retain date2;
if in2 then date2=date;
else do;
if first.id then date2=.;
output;
end;
run;
proc sort;
by id date;
run;
Regards,
Søren
On Mon, 16 Nov 2009 10:59:06 -0500, David Friedman
<harrypotterdhf@EARTHLINK.NET> wrote:
>I have SAS 8.21 installed at my site. I am comparing dates from customers
>from 2 different files. I want to take the customer date from the 2nd file
>closest to the date in the 1st file. A customer in the 1st file might have
2
>different dates but I want the date in the 2nd file closest to each:
>
>Example Input:
>
>File 1
>
>Customer ID date1
>1 01/06/09
>1 02/07/09
>2 02/01/09
>
>File 2
>
>Customer ID date2
>1 03/07/09
>1 04/09/09
>1 04/30/09
>2 03/06/09
>2 07/07/09
>
>Desired Output:
>
>Customer date1 date2
>1 01/06/09 03/07/09
>1 02/07/09 03/07/09
>2 02/01/09 03/06/09