home *** CD-ROM | disk | FTP | other *** search
- Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
- Path: sparky!uunet!paladin.american.edu!auvm!SWIRL.MONSANTO.COM!GIBES
- Message-ID: <9208201855.AA03617@tin.monsanto.com>
- Newsgroups: bit.listserv.sas-l
- Date: Thu, 20 Aug 1992 13:55:16 -0500
- Reply-To: Kernon Gibes <gibes@SWIRL.MONSANTO.COM>
- Sender: "SAS(r) Discussion" <SAS-L@UGA.BITNET>
- From: Kernon Gibes <gibes@SWIRL.MONSANTO.COM>
- Subject: RE: Subsetting data set
- Comments: To: SAS-L@uga.cc.uga.edu@tin.monsanto.com
- Comments: cc: GIBES@tin.monsanto.com
- Lines: 81
-
- CONTENT: Response (to subsetting to baseline data)
- SUMMARY: May be able to use special order of data to do subsetting
- REL/PLTF: na/na
- E-ADDR: gibes@swirl.monsanto.com
- NAME: Kernon Gibes
- DATE: 20 August 1992
-
- Howard S.'s suggestion is fine. But I noticed that it appears that the
- baseline data for a given ID always appears together and before the
- non-baseline data. ***IF*** this is ALWAYS true, one might be able to
- exploit this structure as indicated below. Note that the code won't
- work at all unless this is true: baseline values together for each ID
- *AND* baseline values before the non-baseline data *AND* baseline data
- separated from non-baseline data by at least one other ID! This is all
- true in the example data, but perhaps not in the real data set.
-
- Original, example data:
-
- ID DATE VAR1 VAR1 VAR3........
- 101 8/10/90 1 2 3
- 101 8/11/90 2 2 1
- 101 8/12/90 1 1 2
- 102 5/1/91 1 1 3
- 102 5/3/91 2 3 3
- 103 8/5/91 3 3 1
- 103 8/7/91 1 1 1
- 101 8/4/91 3 3 2
- 101 8/5/91 2 2 3
- 103 8/1/92 1 1 1
- 107 10/1/90 1 2 2
- 107 10/3/90 2 3 1
- 102 4/29/92 3 2 1
- 102 4/30/92 2 2 2
- 104 6/23/90 3 3 3
- 104 6/24/90 3 1 2
- 104 6/26/90 1 2 3
-
- ___ SAS program ________________________________________________________
-
- data temp;
- set test;
- by notsorted id;
- if first.id then idgrp+1;
- run;
-
- proc sort data=temp;
- by id idgrp;
- run;
-
- data baseline;
- retain flag;
- set temp; by id idgrp;
- if first.id then flag=1;
- if flag then output;
- if flag and last.idgrp then flag=0;
- drop idgrp flag;
- run;
-
- proc print;
- run;
-
- ___ end of SAS program _________________________________________________
-
- which yields:
-
- ___ SAS Listing ________________________________________________________
-
- OBS ID DATE VAR1 VAR2 VAR3
-
- 1 101 8/10/90 1 2 3
- 2 101 8/11/90 2 2 1
- 3 101 8/12/90 1 1 2
- 4 102 5/1/91 1 1 3
- 5 102 5/3/91 2 3 3
- 6 103 8/5/91 3 3 1
- 7 103 8/7/91 1 1 1
- 8 104 6/23/90 3 3 3
- 9 104 6/24/90 3 1 2
- 10 104 6/26/90 1 2 3
- 11 107 10/1/90 1 2 2
- 12 107 10/3/90 2 3 1
-