Date: Mon, 11 Mar 1996 09:05:00 -0500
Reply-To: fu.m@PG.COM
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Min Fu <fu.m@PG.COM>
Subject: Re: Merging two tables in SQL
Message authorized by:
: /S=schnekf@GOV.ON.CA/OU=SMTP/O=1.UCN.GO.1/P=PROCTERGAMBLE/A=MCI/C=US/ at c
Frank,
You may try the following codes(tested) for this particular merge.
proc sql;
create table MERGED as
select DATA2.KEYVAR
,DATA1.DATAVAR
from DATA2
left
join DATA1
on DATA2.KEYVAR = DATA1.KEYVAR
;
quit;
---------
Min Fu
Trilogy Consulting at P&G
fu.m@pg.com
______________________________ Reply Separator _________________________________
Subject: Merging two tables in SQL
Author: (INTERNET)SAS-L@UGA.CC.UGA.EDU at external
Date: 3/5/96 10:52 AM
Hello,
I'm trying to use SQL to merge two tables (say 1 and 2) on one or more common
key variables. Table 1 also has data variables, and may not have all levels of
the key variables; table 2 has all unique levels of just the key variables. The
merged table should have all levels of the key variables, with data variables
set to missing for obs not found in Table 1. E.g.
Table 1 (column 1 = key variable, column 2 = data variable):
A 10
B 20
E 30
Table 2 (column 1 = key variable):
A
B
C
D
E
Merged Table:
A 10
B 20
C .
D .
E 30
Simple enough in a data step, but I'm having a difficult
time getting this to work in SQL. Any help much
appreciated.
Thanks.
Frank.
--
Frank Schnekenburger || When I grow up I want to be a
Tree Improvement Data Analyst || Third Stage Guild Navigator
Ministry of Natural Resources || -----------------------------
schnekf@gov.on.ca || lI' veQ, lab veQ