home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 11 / PCPP11.iso / utils / frogbit / fb-097.exe / FREQ.FB < prev    next >
Encoding:
Text File  |  1997-02-04  |  1.4 KB  |  55 lines

  1.  
  2. // example: extract data from SAS tabular output
  3.  
  4. // the data is written in comma-separated format
  5.  
  6.  
  7. input "freqtab.lis"
  8.  
  9. do while (someLeft input)
  10.  
  11.   // find the next table and extract the factors
  12.   skip lines until (line matches " CONTROLLING FOR COUNTRY=~(country) SEX=~(sex) STAGE=~(stage)")
  13.   leave if (not found)
  14.  
  15.   // find the table header line
  16.   skip lines until (line matches " Frequency|~(rest)")
  17.   error if (not found) "end of file - expecting 'Frequency' line"
  18.  
  19.   // extract the years from the table header line
  20.   set years equal to ""
  21.   do while (rest matches " ~(year)|~(rest)")
  22.     write year to years
  23.   loop
  24.  
  25.   // skip dashes and read first line of counts
  26.   read
  27.   read
  28.  
  29.   // process counts lines in table
  30.   do until (line matches " Total~")
  31.  
  32.     // extract age
  33.     error if (not (line matches " ~(age) |~(rest)")) ("age+counts line expected: '" line "'")
  34.  
  35.     // extract the counts from the counts line
  36.     set counts equal to ""
  37.     do while (rest matches " ~(count) |~(rest)")
  38.       write count to counts
  39.     loop
  40.  
  41.     // merge this table's data to the comma-delimited output
  42.     write (years | "," | country | "," | sex | "," | stage | "," | age | "," | counts)
  43.  
  44.     // skip dashes and read next line of counts
  45.     read
  46.     read
  47.   loop
  48.  
  49.   // comment out the next line to make the program run faster
  50.   refresh
  51.  
  52. loop
  53.  
  54. output "freqout.csv"
  55.