home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / bit / listserv / sasl / 3823 < prev    next >
Encoding:
Text File  |  1992-08-20  |  3.3 KB  |  95 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!paladin.american.edu!auvm!SWIRL.MONSANTO.COM!GIBES
  3. Message-ID: <9208201855.AA03617@tin.monsanto.com>
  4. Newsgroups: bit.listserv.sas-l
  5. Date:         Thu, 20 Aug 1992 13:55:16 -0500
  6. Reply-To:     Kernon Gibes <gibes@SWIRL.MONSANTO.COM>
  7. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  8. From:         Kernon Gibes <gibes@SWIRL.MONSANTO.COM>
  9. Subject:      RE: Subsetting data set
  10. Comments: To: SAS-L@uga.cc.uga.edu@tin.monsanto.com
  11. Comments: cc: GIBES@tin.monsanto.com
  12. Lines: 81
  13.  
  14.  CONTENT:   Response (to subsetting to baseline data)
  15.  SUMMARY:   May be able to use special order of data to do subsetting
  16.  REL/PLTF:  na/na
  17.  E-ADDR:    gibes@swirl.monsanto.com
  18.  NAME:      Kernon Gibes
  19.  DATE:      20 August 1992
  20.  
  21. Howard S.'s suggestion is fine.  But I noticed that it appears that the
  22. baseline data for a given ID always appears together and before the
  23. non-baseline data.  ***IF*** this is ALWAYS true, one might be able to
  24. exploit this structure as indicated below.  Note that the code won't
  25. work at all unless this is true: baseline values together for each ID
  26. *AND* baseline values before the non-baseline data *AND* baseline data
  27. separated from non-baseline data by at least one other ID!  This is all
  28. true in the example data, but perhaps not in the real data set.
  29.  
  30. Original, example data:
  31.  
  32.           ID     DATE    VAR1  VAR1  VAR3........
  33.           101    8/10/90  1     2     3
  34.           101    8/11/90  2     2     1
  35.           101    8/12/90  1     1     2
  36.           102    5/1/91   1     1     3
  37.           102    5/3/91   2     3     3
  38.           103    8/5/91   3     3     1
  39.           103    8/7/91   1     1     1
  40.           101    8/4/91   3     3     2
  41.           101    8/5/91   2     2     3
  42.           103    8/1/92   1     1     1
  43.           107    10/1/90  1     2     2
  44.           107    10/3/90  2     3     1
  45.           102    4/29/92  3     2     1
  46.           102    4/30/92  2     2     2
  47.           104    6/23/90  3     3     3
  48.           104    6/24/90  3     1     2
  49.           104    6/26/90  1     2     3
  50.  
  51. ___ SAS program ________________________________________________________
  52.  
  53. data temp;
  54.   set test;
  55.   by notsorted id;
  56.   if first.id then idgrp+1;
  57. run;
  58.  
  59. proc sort data=temp;
  60.   by id idgrp;
  61. run;
  62.  
  63. data baseline;
  64.   retain flag;
  65.   set temp; by id idgrp;
  66.   if first.id then flag=1;
  67.   if flag then output;
  68.   if flag and last.idgrp then flag=0;
  69.  drop idgrp flag;
  70. run;
  71.  
  72. proc print;
  73. run;
  74.  
  75. ___ end of SAS program _________________________________________________
  76.  
  77. which yields:
  78.  
  79. ___ SAS Listing ________________________________________________________
  80.  
  81.              OBS     ID     DATE      VAR1    VAR2    VAR3
  82.  
  83.                1    101    8/10/90      1       2       3
  84.                2    101    8/11/90      2       2       1
  85.                3    101    8/12/90      1       1       2
  86.                4    102    5/1/91       1       1       3
  87.                5    102    5/3/91       2       3       3
  88.                6    103    8/5/91       3       3       1
  89.                7    103    8/7/91       1       1       1
  90.                8    104    6/23/90      3       3       3
  91.                9    104    6/24/90      3       1       2
  92.               10    104    6/26/90      1       2       3
  93.               11    107    10/1/90      1       2       2
  94.               12    107    10/3/90      2       3       1
  95.