| Date: | Thu, 29 Jul 1999 16:42:36 -0400 |
| Reply-To: | murphym2@NATIONWIDE.COM |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "Michael F. Murphy" <murphym2@NATIONWIDE.COM> |
| Subject: | Re: merge correction |
|
| Content-Type: | text/plain; charset=us-ascii |
|---|
Thanks to Nancy Brucken, Bill Droogendyk, and Ian Whitlock who caught my error.
Instead of
and (a.date1 - b.date2 < abs(3));
the line should read:
and (abs(a.date1 - b.date2) <= 3);
---------------------- Forwarded by Michael F Murphy/Nationwide/NWIE on
7/29/1999 01:39:01 PM ---------------------------
Michael F Murphy
P&C Systems
Portland OR-01-21
(503) 797-8921
(503) 797-8961
7/29/1999 12:31:00 PM
Location:
Phone:
Fax:
From: Michael F Murphy on 07/29/99 03:31 PM EDT
To: Max F <lafon18@YAHOO.COM>
cc: SAS-L@LISTSERV.UGA.EDU
Subject: Re: merge (Document link not converted)
I used PROC SQL.
Note that my answer is not the same as yours:
code:
data dataset1;
input @1 date1 date7. id filenum exp;
cards;
01jan98 2 5 10
12jan98 4 6 20
23jan98 5 7 50
31jan98 5 7 40
10feb98 7 9 45
;;
run;
data dataset2;
input @1 date2 date7. id filenum pr;
cards;
01jan98 2 6 3
02jan98 2 5 3
14jan98 4 6 3
20jan98 5 7 3
31jan98 5 7 3
;;
run;
proc sql;
create table dataset3 as
select a.date1,
b.date2,
b.id,
b.filenum,
a.exp,
b.pr
from dataset1 a,
dataset2 b
where a.id=b.id
and a.filenum=b.filenum
and (a.date1 - b.date2 < abs(3));
quit;
proc print data=dataset3;
format date1 date2 date9.;
run;
Answer:
OBS DATE1 DATE2 ID FILENUM EXP PR
1 01JAN1998 02JAN1998 2 5 10 3
2 12JAN1998 14JAN1998 4 6 20 3
3 23JAN1998 31JAN1998 5 7 50 3
4 31JAN1998 31JAN1998 5 7 40 3
Max F <lafon18@YAHOO.COM> on 07/29/99 10:31:22 AM
From: Max F <lafon18@YAHOO.COM> on 07/29/99 10:31 AM
Please respond to Max F <lafon18@YAHOO.COM>
To: SAS-L@LISTSERV.UGA.EDU
cc: (bcc: Michael F Murphy/Nationwide/NWIE)
Subject: merge
Hello,
I need to merge two datasets based on clients id and file number.
Dataset one has:
date id filenum pr
01jan98 2 5 10
12jan98 4 6 20
23jan98 5 7 50
31jan98 5 7 40
10feb98 7 9 45
Dataset Two:
date id filenum exp
01jan98 2 6 3
02jan98 2 5 3
14jan98 4 6 3
20jan98 5 7 3
31jan98 5 7 3
I want to get all the fields in both datasets based on id and
filenum(both should match), and each date in Dataset One needs to be
matched with a row in Dataset Two where the date is within three days.
Therefore, the merged dataset is:
date id filenum exp pr
01jan98 2 5 10
02jan98 2 5 3
12jan98 4 6 20
14jan98 4 6 3
23jan98 5 7 50
20jan98 5 7 3
31jan98 5 7 3 40
'10feb98' in Dataset One does not match with any row in Dataset Two, so
it is excluded. '01jan98' in Dataset Two does not match 'id' and
'filenum' in Dataset One, it is out, too.
Please reply to my account as I am not subscribed to this mailing list.
Many thanks in advance.
Max
_____________________________________________________________
Do You Yahoo!?
Free instant messaging and more at http://messenger.yahoo.com
|