home *** CD-ROM | disk | FTP | other *** search
- Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
- Path: sparky!uunet!gatech!paladin.american.edu!auvm!NIHCU.BITNET!HIS
- Message-ID: <SAS-L%92073112001480@UGA.CC.UGA.EDU>
- Newsgroups: bit.listserv.sas-l
- Date: Fri, 31 Jul 1992 11:59:34 EDT
- Reply-To: Howard Schreier <HIS@NIHCU.BITNET>
- Sender: "SAS(r) Discussion" <SAS-L@UGA.BITNET>
- From: Howard Schreier <HIS@NIHCU.BITNET>
- Subject: Re: Problem with SQL
- Lines: 54
-
- CONTENT: Response
- SUMMARY: SQL join is counterpart to SAS MERGE, with differences
- REL/PLTF: 6.06+
-
- > I've been following the enthusiastic discussion about the integration of
- > SQL in Base SAS... Right now i am converting a very big 5.18 AF-Prog-Lib
- > to SAS Rel 6.07 on MVS. We have lots of screens, that generate data-
- > selection Statements in background: formerly data steps with subsetting
- > ifs, now SQL views with long select from...... where ........ statements.
- > Used to SAS programming logic i have a very important but unsolved
- >
- > problem: I have to merge two datasets in the following manner:
- > data ;
- > merge dsa (in=a) dsb ;
- > if a ; /* only recs with contibution of dsa */
- > by key; /* both datasets are sorted by key... */
- > if first.key; /* keep only first appearance of rec. with keyvalue */
- > run;
- > The code might be strange, but that's the way it was written...
- > I think the idea is to merge two datasets to have vars from both
- > datasets, keep only recs with info from both datasets or dataset a
- > and finally keep only the first record if many recs have the
- > same key.
- >
- > I really don't know how to accomplish this in SQL... (this is not
- > criticism on SQL but confessing having more experience in datastep
- > than SQL...)
- >
- > I really appreciate ANY hint on this, because the problem is very
- > important and urgent to my customers !!!
-
- This is a LEFT JOIN ON DSA.KEY=DSB.KEY
-
- Converting the FIRST.KEY filter is a little more difficult,
- since SQL doesn't recognize order or sequence on the input
- side. You will have to develop a different condition; if
- there are sequence numbers in the data, you could GROUP BY
- KEY and select rows HAVING minimum sequence numbers.
-
- Remember that if KEY values repeat in both tables, the SQL
- join works differently than a DATA step MERGE. If DSA has
- three rows with KEY=95 and DSB has two rows with KEY=95, the
- join will generate 3x2=6 rows, whereas the MERGE will
- generate max(3,2)=3.
- >
- > Yours sincerely Andi Diggelmann (SAS Software Consultant Univ. Zuerich
- > Switzerland
-
- /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
- \ Howard Schreier, U.S. Dept. of Commerce, Washington /
- / MVS 5.18 & 6.07 \
- \ Voice: (202) 377-4180 BITNET: HIS@NIHCU /
- / Fax: (202) 377-4614 INTERNET: HIS@CU.NIH.GOV \
- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
-