home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / bit / listserv / sasl / 5539 < prev    next >
Encoding:
Text File  |  1993-01-06  |  2.6 KB  |  63 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!elroy.jpl.nasa.gov!usc!zaphod.mps.ohio-state.edu!darwin.sura.net!paladin.american.edu!auvm!UNC.BITNET!UPHILG
  3. Message-ID: <SAS-L%93010617090233@VTVM2.CC.VT.EDU>
  4. Newsgroups: bit.listserv.sas-l
  5. Date:         Wed, 6 Jan 1993 17:08:00 EST
  6. Reply-To:     "Philip Gallagher,(919)966-1065" <UPHILG@UNC.BITNET>
  7. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  8. From:         "Philip Gallagher,(919)966-1065" <UPHILG@UNC.BITNET>
  9. Subject:      Re: discard superfluous observations *HOW*?
  10. Comments: To: Patrick Haggard <ph@PHYSIOLOGY.OXFORD.AC.UK>
  11. Lines: 50
  12.  
  13. Patrick Haggard wrote:                                                  c.uk
  14.  
  15. > I have some data containing between n and m observations in each
  16. > of C conditions.  I would like to have exactly n observations in
  17. > each condition, so that my design is balanced: I'm fairly happy that
  18. > discarding the excess observations shouldn't change things too much.
  19. > My question: can anyone suggest a way to discard the excess
  20. > observations in a SAS data step, and to number the remaining
  21. > observations 1...n for each condition.
  22.  
  23.     Ah!  This is, in principle, an easy one.  Since I will not
  24.     have time to test the code I may wind up very embarassed, but
  25.     here goes.  (Even if I make some coding mistakes I am sure
  26.     the general structure will work.)
  27.  
  28.     Assume data resides in a SAS dataset called WORK.OLD and
  29.     that the condition-variable is named CONDIT.  The following
  30.     should work just fine:
  31.  
  32.     PROC SORT DATA=WORK.OLD OUT=WORK.SORDID;
  33.         BY CONDIT;
  34.     RUN;
  35.  
  36.     DATA BALANCED(LABEL='Dataset w/n observations/condition')
  37.          EXCESS  (LABEL='Dataset w/excess observations')
  38.          ;
  39.         SET WORK.SORDID;
  40.         BY CONDIT;      * <=== This creates the FIRST.CONDIT var;
  41.         RETAIN NUMBER;  * <=== Don't initialize this var automatically;
  42.  
  43.         *  Initialize NUMBER each time a new condition is encountered;
  44.         IF (FIRST.CONDIT EQ 1) THEN NUMBER = 0;
  45.  
  46.         NUMBER = NUMBER + 1;
  47.         *  Be sure to substitute the desired value for "n"
  48.            in the following statement;
  49.         IF (NUMBER LE n) THEN OUTPUT BALANCED;
  50.         ELSE OUTPUT EXCESS;
  51.     RUN;
  52.  
  53.     *  Note that I don't just "discard" the unwanted observations.
  54.        I recommend that one always take at least a cursory look
  55.        at the discarded/omitted observations first.  Every once
  56.        in a while there is a hideous surprise concealed in what
  57.        one thought could be discarded.  Do a MEANS and a FREQ,
  58.        at least.;
  59.  
  60.                           Phil Gallagher
  61.                           UNC Biostatistics
  62.                           uphilg@unc
  63.