home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / bit / listserv / sasl / 3519 < prev    next >
Encoding:
Text File  |  1992-07-31  |  2.8 KB  |  66 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!gatech!paladin.american.edu!auvm!NIHCU.BITNET!HIS
  3. Message-ID: <SAS-L%92073112001480@UGA.CC.UGA.EDU>
  4. Newsgroups: bit.listserv.sas-l
  5. Date:         Fri, 31 Jul 1992 11:59:34 EDT
  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: Problem with SQL
  10. Lines: 54
  11.  
  12. CONTENT:  Response
  13. SUMMARY:  SQL join is counterpart to SAS MERGE, with differences
  14. REL/PLTF: 6.06+
  15.  
  16. > I've been following the enthusiastic discussion about the integration of
  17. > SQL in Base SAS... Right now i am converting a very big 5.18 AF-Prog-Lib
  18. > to SAS Rel 6.07 on MVS. We have lots of screens, that generate data-
  19. > selection Statements in background: formerly data steps with subsetting
  20. > ifs, now SQL views with long select from...... where ........ statements.
  21. > Used to SAS programming logic i have a very important but unsolved
  22. >
  23. > problem: I have to merge two datasets in the following manner:
  24. >    data ;
  25. >      merge dsa (in=a) dsb ;
  26. >        if a ;     /* only recs with contibution of dsa */
  27. >        by key;    /* both datasets are sorted by key... */
  28. >      if first.key;  /* keep only first appearance of rec. with keyvalue */
  29. >    run;
  30. > The code might be strange, but that's the way it was written...
  31. > I think the idea is to merge two datasets to have vars from both
  32. > datasets, keep only recs with info from both datasets or dataset a
  33. > and finally keep only the first record if many recs have the
  34. > same key.
  35. >
  36. > I really don't know how to accomplish this in SQL...  (this is not
  37. > criticism on SQL but confessing having more experience in datastep
  38. > than SQL...)
  39. >
  40. > I really appreciate ANY hint on this, because the problem is very
  41. > important and urgent to my customers !!!
  42.  
  43. This is a LEFT JOIN ON DSA.KEY=DSB.KEY
  44.  
  45. Converting the FIRST.KEY filter is a little more  difficult,
  46. since  SQL  doesn't recognize order or sequence on the input
  47. side.  You will have to develop a  different  condition;  if
  48. there  are  sequence numbers in the data, you could GROUP BY
  49. KEY and select rows HAVING minimum sequence numbers.
  50.  
  51. Remember that if KEY values repeat in both tables,  the  SQL
  52. join  works  differently than a DATA step MERGE.  If DSA has
  53. three rows with KEY=95 and DSB has two rows with KEY=95, the
  54. join  will  generate  3x2=6  rows,  whereas  the  MERGE will
  55. generate max(3,2)=3.
  56. >
  57. > Yours sincerely Andi Diggelmann (SAS Software Consultant Univ. Zuerich
  58. > Switzerland
  59.  
  60. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  61. \   Howard Schreier, U.S. Dept. of Commerce, Washington    /
  62. /                     MVS 5.18 & 6.07                      \
  63. \   Voice: (202) 377-4180        BITNET: HIS@NIHCU         /
  64. /   Fax:   (202) 377-4614      INTERNET: HIS@CU.NIH.GOV    \
  65. \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  66.