home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / bit / listserv / sasl / 3760 < prev    next >
Encoding:
Text File  |  1992-08-17  |  2.6 KB  |  90 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%92081714175451@UGA.CC.UGA.EDU>
  4. Newsgroups: bit.listserv.sas-l
  5. Date:         Mon, 17 Aug 1992 14:15:28 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: SQL delete statement
  10. Lines: 78
  11.  
  12. CONTENT:  Response
  13. SUMMARY:  Use SQL correlated subquery to implement "delete list"
  14. REL/PLTF: 6.06+
  15.  
  16. From Don MacQueen (macq@miguel.llnl.gov):
  17.  
  18. > I have a very large dataset, from which I would like to
  19. > delete a number of observations. This dataset is large
  20. > enough that I am running short on disk space. The
  21. > information about which cases to delete comes from another
  22. > dataset, based on some key variables.
  23. >
  24. > Normally, I would do something like this:
  25. >
  26. > data new;
  27. >   merge big dels (in=indel);
  28. >   by area analyte;
  29. >   if indel then delete;
  30. >   run;
  31. >
  32. > Where there are many observations in big for each
  33. > combination of area and analyte, but each combination of
  34. > area and analyte only appears once in dels.
  35. >
  36. > I thought I'd look at proc sql. Seems like something such
  37. > as
  38. >
  39. > proc sql;
  40. >   delete from big
  41. >     where big.area=dels.area and big.analyte=dels.analyte;
  42. >
  43. > ought to work, but It doesn't, and I don't know SQL well
  44. > enough to fix it.
  45.  
  46. Try adapting the example on the bottom of p. 129 of the  SQL
  47. FM:
  48.  
  49.   delete from big where exists
  50.    (select * from dels where
  51.     big.area=dels.area and big.analyte=dels.analyte);
  52.  
  53. Test table BIG (before):
  54.  
  55.     AREA   ANALYTE     OTHER
  56. ----------------------------
  57.        1         1        22
  58.        1         2        33
  59.        1         2        44
  60.        2         1        55
  61.        2         2        66
  62.        3         3        77
  63.  
  64. Test table DELS:
  65.  
  66.     AREA   ANALYTE
  67. ------------------
  68.        1         2
  69.        2         2
  70.  
  71. Test table BIG (after):
  72.  
  73.     AREA   ANALYTE     OTHER
  74. ----------------------------
  75.        1         1        22
  76.        2         1        55
  77.        3         3        77
  78.  
  79. This employees a "correlated subquery"; in  other  words,  a
  80. subquery  which has to be evaluated for each row of the main
  81. table.  I'm not sure that this will be  efficient  for  your
  82. situation.
  83.  
  84. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  85. \   Howard Schreier, U.S. Dept. of Commerce, Washington    /
  86. /                     MVS 5.18 & 6.07                      \
  87. \   Voice: (202) 377-4180        BITNET: HIS@NIHCU         /
  88. /   Fax:   (202) 377-4614      INTERNET: HIS@CU.NIH.GOV    \
  89. \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  90.