home *** CD-ROM | disk | FTP | other *** search
-
- // example: extract data from SAS tabular output
-
- // the data is written in comma-separated format
-
-
- input "freqtab.lis"
-
- do while (someLeft input)
-
- // find the next table and extract the factors
- skip lines until (line matches " CONTROLLING FOR COUNTRY=~(country) SEX=~(sex) STAGE=~(stage)")
- leave if (not found)
-
- // find the table header line
- skip lines until (line matches " Frequency|~(rest)")
- error if (not found) "end of file - expecting 'Frequency' line"
-
- // extract the years from the table header line
- set years equal to ""
- do while (rest matches " ~(year)|~(rest)")
- write year to years
- loop
-
- // skip dashes and read first line of counts
- read
- read
-
- // process counts lines in table
- do until (line matches " Total~")
-
- // extract age
- error if (not (line matches " ~(age) |~(rest)")) ("age+counts line expected: '" line "'")
-
- // extract the counts from the counts line
- set counts equal to ""
- do while (rest matches " ~(count) |~(rest)")
- write count to counts
- loop
-
- // merge this table's data to the comma-delimited output
- write (years | "," | country | "," | sex | "," | stage | "," | age | "," | counts)
-
- // skip dashes and read next line of counts
- read
- read
- loop
-
- // comment out the next line to make the program run faster
- refresh
-
- loop
-
- output "freqout.csv"
-