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: <9207221910.AA15519@tin.monsanto.com>
- Newsgroups: bit.listserv.sas-l
- Date: Wed, 22 Jul 1992 14:10:11 -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: multiple identical id vars problem
- Comments: To: SAS-L@uga.cc.uga.edu@tin.monsanto.com
- Comments: cc: GIBES@tin.monsanto.com
- Lines: 70
-
- CONTENT: Response to "multiple identical id vars problem"
- SUMMARY: Re-shaping data set with series of PROC TRANSPOSEs
- REL/PLTF: 6.04/ PC DOS
- E-ADDR: gibes@swirl.monsanto.com
- NAME: Kernon Gibes
- PHONE: (708) 506-2873
- DATE/TIME: 22 July 1992, 2:11 p.m. CDT
-
- Ed Silverman wrote that he wanted to re-organize:
-
- ID CODE TERM DATE
-
- 002162706 292 901 900309
- 002162706 292 901 900403
- 002254401 299 891 890201
- 002254401 299 901 900303
- 002254401 276 901 900405
-
- into (one observation per ID, multiple variables):
-
- ID CODE TERM DATE CODE2 TERM2 DATE2 CODE3 TERM3 DATE3
-
- 002162706 292 901 900309 299* 901 900403
- 002254401 299 891 890201 299 901 900303 299** 901 900405
-
- (I'm assuming that 299* should be 292 and 299** should be 276??????)
-
- Since this is 6.04 he can't use SQL [ha ha ;-) ]. This could be done
- easily enough in a data step with arrays and LAST. processing, but
- since it's not clear that we know in advance the maximum number of
- unique ID values, I've given one approach using PROC TRANSPOSEs below.
- This doesn't give the desired order of variables and missing values
- might present problems, but I'll leave the data step approach to
- someone else!
-
- data test;
- input
- ID CODE TERM DATE;
- cards;
- 002162706 292 901 900309
- 002162706 292 901 900403
- 002254401 299 891 890201
- 002254401 299 901 900303
- 002254401 276 901 900405
- ;
- run;
-
- proc sort data=test;
- by id;
- run;
-
- proc transpose data=test out=long1 prefix=code;
- by id;
- var code;
- run;
-
- proc transpose data=test out=long2 prefix=term;
- by id;
- var term;
- run;
-
- proc transpose data=test out=long3 prefix=date;
- by id;
- var date;
- run;
-
- data final;
- merge long1 long2 long3;
- by id;
- run;
-