home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / bit / listserv / sasl / 3397 < prev    next >
Encoding:
Text File  |  1992-07-22  |  2.3 KB  |  84 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!paladin.american.edu!auvm!SWIRL.MONSANTO.COM!GIBES
  3. Message-ID: <9207221910.AA15519@tin.monsanto.com>
  4. Newsgroups: bit.listserv.sas-l
  5. Date:         Wed, 22 Jul 1992 14:10:11 -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: multiple identical id vars problem
  10. Comments: To: SAS-L@uga.cc.uga.edu@tin.monsanto.com
  11. Comments: cc: GIBES@tin.monsanto.com
  12. Lines: 70
  13.  
  14.  CONTENT:   Response to "multiple identical id vars problem"
  15.  SUMMARY:   Re-shaping data set with series of PROC TRANSPOSEs
  16.  REL/PLTF:  6.04/ PC DOS
  17.  E-ADDR:    gibes@swirl.monsanto.com
  18.  NAME:      Kernon Gibes
  19.  PHONE:     (708) 506-2873
  20.  DATE/TIME: 22 July 1992, 2:11 p.m. CDT
  21.  
  22.  Ed Silverman wrote that he wanted to re-organize:
  23.  
  24. ID           CODE  TERM  DATE
  25.  
  26. 002162706    292  901   900309
  27. 002162706    292  901   900403
  28. 002254401    299  891   890201
  29. 002254401    299  901   900303
  30. 002254401    276  901   900405
  31.  
  32. into (one observation per ID, multiple variables):
  33.  
  34. ID         CODE TERM DATE  CODE2 TERM2 DATE2  CODE3 TERM3 DATE3
  35.  
  36. 002162706  292  901 900309 299*  901   900403
  37. 002254401  299  891 890201 299   901   900303  299** 901  900405
  38.  
  39.  (I'm assuming that 299* should be 292 and 299** should be 276??????)
  40.  
  41.  Since this is 6.04 he can't use SQL [ha ha ;-) ].  This could be done
  42.  easily enough in a data step with arrays and LAST. processing, but
  43.  since it's not clear that we know in advance the maximum number of
  44.  unique ID values, I've given one approach using PROC TRANSPOSEs below.
  45.  This doesn't give the desired order of variables and missing values
  46.  might present problems, but I'll leave the data step approach to
  47.  someone else!
  48.  
  49. data test;
  50. input
  51. ID           CODE  TERM  DATE;
  52. cards;
  53. 002162706    292  901   900309
  54. 002162706    292  901   900403
  55. 002254401    299  891   890201
  56. 002254401    299  901   900303
  57. 002254401    276  901   900405
  58. ;
  59. run;
  60.  
  61. proc sort data=test;
  62. by id;
  63. run;
  64.  
  65. proc transpose data=test out=long1 prefix=code;
  66. by id;
  67. var code;
  68. run;
  69.  
  70. proc transpose data=test out=long2 prefix=term;
  71. by id;
  72. var term;
  73. run;
  74.  
  75. proc transpose data=test out=long3 prefix=date;
  76. by id;
  77. var date;
  78. run;
  79.  
  80. data final;
  81. merge long1 long2 long3;
  82. by id;
  83. run;
  84.