home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / bit / listserv / sasl / 4983 < prev    next >
Encoding:
Text File  |  1992-11-09  |  4.3 KB  |  95 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!stanford.edu!bcm!convex!news.oc.com!eff!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!darwin.sura.net!paladin.american.edu!auvm!BARUCH.BITNET!TEJERA
  3. Message-ID: <SAS-L%92110915363768@UGA.CC.UGA.EDU>
  4. Newsgroups: bit.listserv.sas-l
  5. Date:         Mon, 9 Nov 1992 15:18:28 EST
  6. Reply-To:     Philip Tejera <TEJERA@BARUCH.BITNET>
  7. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  8. From:         Philip Tejera <TEJERA@BARUCH.BITNET>
  9. Subject:      Re: Data Reshaping ?
  10. In-Reply-To:  Message of Wed, 4 Nov 1992 16:56:49 EST from <NY922195@PACEVM>
  11. Lines: 82
  12.  
  13. On Wed, 4 Nov 1992 16:56:49 EST Chris said:
  14. >Hi ! I've got a data reshaping problem, compounded by the fact some
  15. >of the data is stored in permanent SAS datasets and the rest is con-
  16. >tained in raw datasets. In both cases, the data looks like this:
  17. >
  18. >   DEPNO    DEPT    YR    V1    V2    V3    V4    V5
  19. >   121      MIS     80    10    11    12    13    14
  20. >   121      MIS     81    15    16    17    18    19
  21. >   121      MIS     82    20    21    22    23    24
  22. >   144      COMM    80    41    42    43    44    45
  23. >   144      COMM    81    46    47    48    49    50
  24. >   144      COMM    82    51    52    53    54    55
  25. >
  26. >The actual datasets have 15 records per DEPNO and 40 variables per
  27. >record. The data originally came from SQL tables (IBM's SQL/DS dbms)
  28. >before being dumped to flat files and then converted (in some cases)
  29. >to permanent SAS datasets.
  30. >
  31. >What I want is to fold the individual rows back into one record, with
  32. >the data values (V1 thru V5 in the above example) forming a 3 x 5 array
  33. >(15 x 40 for the real data) for each record, such as the following:
  34. >
  35. >   121 MIS  10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
  36. >   144 COMM 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
  37. > ...
  38. >The datasets/files are fairly large: 10,000 to 25,000 records.
  39. >We are running SAS 6.07 under VM/ESA...
  40.  
  41. Although I have seen the previously posted answer on using Proc Transpose
  42. to do this, I remain dissatisfied. SAS is a very powerful tool, but surely
  43. we would want a student to learn the old KISS rule (Keep It Simple ...).
  44. Also, with a "fairly large dataset", efficient techniques should be used.
  45.  
  46. There seems to be a slight error in the question, namely the statement
  47. that the resulting one record is "3 x 5", when really it is "1 x 15"
  48. from 3 arrays each "1 x 5", but I think the meaning is clear.
  49.  
  50. The solution for the raw datasets is to use the Input statement to read
  51. more than one record per observation. See SAS Language Reference, Version
  52. 6, First Edition, page 400, for instance, and the preceding material on
  53. line pointer controls, p. 398 ff. This is nothing fancy, most packages
  54. can do this easily, no doubt that is why the data is in this format.
  55.  
  56. As to the part of the data stored in sas datasets, use of the SET
  57. statement after using the RENAME dataset option should do the trick.
  58. We don't know how these raw and SAS datasets are mixed, but the
  59. Input and Set statements should be able to handle most combinations,
  60. along with the Infile statement to point to the appropriate raw data
  61. file. Also, SAS provides many possibilities for embellishments, such
  62. as checking that there are no missing rows, etc.
  63.  
  64. A simple example would be something like:
  65.  
  66. Data from_raw;
  67.    Infile ...  ;
  68.    Input deptno  dept  $ yr1 v1-v5   /
  69.          deptno2 dept2 $ yr2 v6-v10  /
  70.          deptno3 dept3 $ yr3 v11-v15 ;
  71.  
  72. If the data is already in a SAS dataset, then code something like:
  73.  
  74. Data from_sas;
  75.      Set in1;
  76.      Set in1 (rename=(deptno=deptno2,dept=dept2,yr=yr2,v1=v6,v2=v7,...));
  77.      Set in1 (rename=(deptno=deptno3,dept=dept3,yr=yr3,v1=v11,v2=v12,...));
  78.  
  79. In either example, one would probably also use the Drop statement to get
  80. rid of redundant information, i.e.,
  81.  
  82.      Drop deptno2, dept2, yr2, deptno3, dept3, yr3;
  83.  
  84. Of course, a wise programmer would first test that the information was in
  85. fact redundant, but I leave that up to the reader, with the hint that
  86. the Lostcard statement might be worth looking up.
  87.  
  88. No, I didn't test this code, since the intent is to show the direction
  89. for study, and some details are missing. The main point is that it is
  90. possible to do this reshaping with only one pass of the data.
  91.  
  92. Other useful references would be the SAS Applications Guide, 1987,
  93. and SAS Language and Procedures, Usage, Version 6, First Edition,
  94. especially pp. 57 and following.
  95.