Date: Mon, 9 Sep 2002 14:36:18 GMT
Reply-To: julierog@ix.netcom.com
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Roger Lustig <trovato@BELLATLANTIC.NET>
Subject: Re: merge
Content-Type: text/plain; charset=us-ascii; format=flowed
Kim:
If you sort the input files by ID and *descending* date, this becomes
much easier.
<assumption; file A has only one record per ID.>
<sort steps here>
data merged(keep=id date_b);
flag=0;
do until (last.id);
merge a (rename=(date=date_a))
b (rename=(date=date_b))
;
by id;
if date_a=date_b then flag=1;
if flag=1 then output;
end;
run;
<re-sort if need be>
kin tang wrote:
> Hello,
>
> I need to merge dataset A with dataset B by id and
> date. In the meantime,
> if there is a match, all earlier records prior to the
> matched date need
> to be retrieved as well.
>
> Data A
>
> id date
>
> 123 15jan98
>
>
> Data B
>
> id date
>
> 123 22oct96
> 123 12nov95
> 123 15jan98
> 123 29aug99
> 123 01jan00
>
> So the final dataset would be:
>
> Merged data
>
> id date
>
> 123 22oct96
> 123 12nov95
> 123 15jan98
>
>
> How do I achieve this? Thanks.
>
>
> Kin
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Finance - Get real-time stock quotes
> http://finance.yahoo.com
|