LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2002, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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


Back to: Top of message | Previous page | Main SAS-L page