home *** CD-ROM | disk | FTP | other *** search
- Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
- Path: sparky!uunet!paladin.american.edu!auvm!NIHCU.BITNET!HIS
- Message-ID: <SAS-L%93012209142047@UGA.CC.UGA.EDU>
- Newsgroups: bit.listserv.sas-l
- Date: Fri, 22 Jan 1993 09:12:17 EST
- Reply-To: Howard Schreier <HIS@NIHCU.BITNET>
- Sender: "SAS(r) Discussion" <SAS-L@UGA.BITNET>
- From: Howard Schreier <HIS@NIHCU.BITNET>
- Subject: Re: PROC SQL
- Lines: 74
-
- CONTENT: Response
- SUMMARY: Wrap one SELECT around another
- REL/PLTF: 6.06+
-
- > SQL help please - the following gives me matched records
- > plus all unmatched records from datasets ONE and TWO. I
- > want to restrict the content of BOTH to: matched records
- > (id1=id2) + all unmatched records from dataset TWO +
- > unmatched records from dataset ONE where drg1 = '300'. As
- > an SQL neophyte, no matter what SQL expression I try, I
- > don't get the desired result.
- >
- > options nocenter;
- >
- > data one;
- > input
- > @1 id1 $char3.
- > @5 var1 $char3.
- > @9 drg1 $char3.;
- > cards;
- > 123 on1 300
- > 234 on2 200
- > 345 on3 300
- > ;
- > run;
- >
- > data two;
- > input
- > @1 id2 $char3.
- > @5 var2 $char3.
- > @9 drg2 $char3.;
- > cards;
- > 123 tw1 300
- > 456 tw2 300
- > ;
- > run;
- >
- > proc sql;
- > create table both as
- > select *
- > from one full join two
- > on id1 = id2;
- >
- > proc print data=both;
- > run;
-
- I would just let the outer JOIN work as it is; it will
- return a row with ID1=234 which you don't want. You can
- code a second filter outside your existing SELECT:
-
- select * from (select *
- from one full join two
- on id1 = id2)
- where drg1='300' or id2 is not missing;
-
- This assumes that ID2 is never missing in the original data.
- The result:
-
- ID1 VAR1 DRG1 ID2 VAR2 DRG2
- --------------------------------
- 123 on1 300 123 tw1 300
- 345 on3 300
- 456 tw2 300
-
- PS: The inclusion of a complete simplified example with the
- question made it much easier for me to work with the
- problem.
-
- /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
- \ 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 \
- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
-