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

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!gatech!paladin.american.edu!auvm!NIHCU.BITNET!HIS
  3. Message-ID: <SAS-L%92072710443776@UGA.CC.UGA.EDU>
  4. Newsgroups: bit.listserv.sas-l
  5. Date:         Mon, 27 Jul 1992 10:43:29 EDT
  6. Reply-To:     Howard Schreier <HIS@NIHCU.BITNET>
  7. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  8. From:         Howard Schreier <HIS@NIHCU.BITNET>
  9. Subject:      Combining Diverse Files
  10. Lines: 141
  11.  
  12. CONTENT:  Response
  13. SUMMARY:  Use trailing "@" to read/write repeating fields
  14.  
  15. A user has to combine data from three differently  formatted
  16. external files.  The details:
  17.  
  18. >  First:  Lrecl = 40
  19. >          date (4.)     fid ($7.)   dummy (16.)   itm (5.)      qty (8.)
  20. >             0101        a100001     123986....     45422        34400
  21. >             0101        a100001          .         45666        23455
  22. >              .            .              .             .           .
  23. >             0131        a100001          .         00123        123234
  24. >             0101        a100002          .         12993        123300
  25. >              .           .               .            .            .
  26. >
  27. >  Second:  Lrecl = 110
  28. >            date  fid  itm1  qty1  itm2  qty2  ... itm8  qty8   check
  29. >                                                                  *
  30. >           * the check # is the symbol of how many records belongs to
  31. >             the same fid on the same date.
  32. >
  33. >  Third:   Lrecl = 341
  34. >           fid  date  dummy (19.)  account (2.)  qty1 itm1 ... qty24 itm24
  35. >                                      *                      *     *
  36. >           * account is the symbol of the qty# and itm#.
  37. >             eg:  account = 12  implied from qty1 itm1 to qty12 itm12
  38. >
  39. >   finally I want to manage the dataset as:
  40. >
  41. >       Lrecl = 80
  42. >        fid   date             blank  (67)                       cd (2)
  43. >        fid   date  itm1 (5)  qty1 (8) ... itm5  qty5  blank (2) cd (2)
  44. >                                                                 *
  45. >        * take the card # appart.
  46. >          eg:  cd = 1        is the card included fid date
  47. >               cd = 2 or 3 or ...    is the sequence # of the contant
  48. >                fid itm qty
  49. >               if the qty# & itm# over 5 on the same date in the same fid
  50. >               then cd will be add 1.
  51. >
  52. >   Any advice is appreciated.   Welcome your anser.
  53. > Daisy Hsu
  54. > Bitnet : Daisy@twnmoe10
  55.  
  56. To make things more manageable, I  will  work  with  smaller
  57. field widths (3 for FID, 4 for DUMMY, 1 for ITM, 2 for QTY),
  58. fewer repetitions (3 for the second input file,  4  for  the
  59. third), and a record length of 30 for the output file.
  60.  
  61. Reading the first input is straightforward.  The "+" pointer
  62. control is used to jump over the DUMMY field.
  63.  
  64.    data sub1;
  65.    input date 4. fid $3. +4 itm $1. qty 2.;
  66.    cards;
  67.    0101a10    A12
  68.    1231z99    C21
  69.    ;
  70.  
  71. The second input is messier,  because  some  fields  repeat.
  72. The trailing "@" pointer control holds the input record.
  73.  
  74.    data sub2;
  75.    input date 4. fid $3.    @;
  76.    do across = 1 to 3;
  77.       input itm $1. qty 2.  @;
  78.       * Filter out blank fields;
  79.       if itm ne ' ' then output;
  80.       end;
  81.    cards;
  82.    0101a10G35A44L58 2
  83.    0101a10E01       2
  84.    1231z99N26       1
  85.    ;
  86.  
  87. Note that the CHECK field is not used or even read.  Turning
  88. to the third file, the trailing "@" is again useful.
  89.  
  90.    data sub3;
  91.    input date 4. fid $3. +4 account 2. @;
  92.    do across = 1 to account;
  93.       input itm $1. qty 2.             @;
  94.       output;
  95.       end;
  96.    cards;
  97.    0427h18    04D28C27B26A25
  98.    0427h18    02Y24X23
  99.    0704k10    01W22
  100.    ;
  101.  
  102. If the original files are in the desired sort sequence,  the
  103. subsets  can  now  be  interleaved  and transcribed into the
  104. specified  form   (otherwise,   there   are   two   options:
  105. concatenate  the  subsets,  sort the combined data set, then
  106. create the output; or  sort  the  subsets  separately,  then
  107. interleave as shown).
  108.  
  109.    data _null_;
  110.    set sub1 sub2 sub3; by fid date;
  111.    file print;
  112.    if first.date then do;
  113.       cd = 1;
  114.       * Write header;
  115.       put fid $3. date z4. @29 cd z2.;
  116.       end;
  117.    field + 1;
  118.    if field=1 then do;
  119.       cd + 1;
  120.       * Start new data record, position pointer for field #1, and hold;
  121.       put fid $3. date z4. @29 cd z2. @8 @;
  122.       end;
  123.    put itm $1. qty 2.                    @;
  124.    if field=5 or last.date then do;
  125.       * Release record;
  126.       put;
  127.       field = 0;
  128.       end;
  129.  
  130. The trailing "@" is again  useful,  this  time  for  output.
  131. Also,  note  that  the  two  counters,  CD  and  FIELD,  are
  132. automatically RETAINed  because  they  appear  in  summation
  133. statements.
  134.  
  135. The results, combining the test data shown:
  136.  
  137.    a100101                     01
  138.    a100101A12G35A44L58E 1      02
  139.    h180427                     01
  140.    h180427D28C27B26A25Y24      02
  141.    h180427X23                  03
  142.    k100704                     01
  143.    k100704W22                  02
  144.    z991231                     01
  145.    z991231C21N26               02
  146.  
  147. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  148. \   Howard Schreier, U.S. Dept. of Commerce, Washington    /
  149. /                     MVS 5.18 & 6.07                      \
  150. \   Voice: (202) 377-4180        BITNET: HIS@NIHCU         /
  151. /   Fax:   (202) 377-4614      INTERNET: HIS@CU.NIH.GOV    \
  152. \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  153.