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 (March 1996, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
Comments: cc: schnekf@gov.on.ca

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


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