home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / bit / listserv / sasl / 5719 < prev    next >
Encoding:
Text File  |  1993-01-22  |  2.3 KB  |  86 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!paladin.american.edu!auvm!NIHCU.BITNET!HIS
  3. Message-ID: <SAS-L%93012209142047@UGA.CC.UGA.EDU>
  4. Newsgroups: bit.listserv.sas-l
  5. Date:         Fri, 22 Jan 1993 09:12:17 EST
  6. Reply-To:     Howard Schreier <HIS@NIHCU.BITNET>
  7. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  8. From:         Howard Schreier <HIS@NIHCU.BITNET>
  9. Subject: Re: PROC SQL
  10. Lines: 74
  11.  
  12. CONTENT:  Response
  13. SUMMARY:  Wrap one SELECT around another
  14. REL/PLTF: 6.06+
  15.  
  16. > SQL help please - the following gives me matched records
  17. > plus all unmatched records from datasets ONE and TWO.  I
  18. > want to restrict the content of BOTH to:  matched records
  19. > (id1=id2) + all unmatched records from dataset TWO +
  20. > unmatched records from dataset ONE where drg1 = '300'.  As
  21. > an SQL neophyte, no matter what SQL expression I try, I
  22. > don't get the desired result.
  23. >
  24. > options nocenter;
  25. >
  26. > data one;
  27. > input
  28. > @1 id1  $char3.
  29. > @5 var1 $char3.
  30. > @9 drg1 $char3.;
  31. > cards;
  32. > 123 on1 300
  33. > 234 on2 200
  34. > 345 on3 300
  35. > ;
  36. > run;
  37. >
  38. > data two;
  39. > input
  40. > @1 id2  $char3.
  41. > @5 var2 $char3.
  42. > @9 drg2 $char3.;
  43. > cards;
  44. > 123 tw1 300
  45. > 456 tw2 300
  46. > ;
  47. > run;
  48. >
  49. > proc sql;
  50. > create table both as
  51. > select *
  52. > from one full join two
  53. > on id1 = id2;
  54. >
  55. > proc print data=both;
  56. > run;
  57.  
  58. I would just let the outer JOIN  work  as  it  is;  it  will
  59. return  a  row  with  ID1=234 which you don't want.  You can
  60. code a second filter outside your existing SELECT:
  61.  
  62.    select * from (select *
  63.                  from one full join two
  64.                  on id1 = id2)
  65.       where drg1='300' or id2 is not missing;
  66.  
  67. This assumes that ID2 is never missing in the original data.
  68. The result:
  69.  
  70.    ID1  VAR1  DRG1  ID2  VAR2  DRG2
  71.    --------------------------------
  72.    123  on1   300   123  tw1   300
  73.    345  on3   300
  74.                     456  tw2   300
  75.  
  76. PS:  The inclusion of a complete simplified example with the
  77. question  made  it  much  easier  for  me  to  work with the
  78. problem.
  79.  
  80. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  81. \   Howard Schreier, U.S. Dept. of Commerce, Washington    /
  82. /                     MVS 5.18 & 6.07                      \
  83. \   Voice: (202) 377-4180        BITNET: HIS@NIHCU         /
  84. /   Fax:   (202) 377-4614      INTERNET: HIS@CU.NIH.GOV    \
  85. \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  86.