freq2.pl -- Frequency Counts with Percentages
freq2.pl is a simple extension of freq.pl which provides frequency counts, frequency as a percentage of total count, plus cumulative frequency, and cumulative percentage.
- Show freq2.pl code
- Download: freq2.pl
Limitations:
- Can only print the first 20 characters of a value, although can compute frequencies for longer values.
- The order of values in the output is set by a character sort rather than a numeric sort (the program knows nothing of variable types like numeric or string).
- If you give a column range outside the logical record length of the data, you will still get output, but all values will be null.
- Since the program summarizes values, if you have dots in the data (as SAS missing), they will be counted. And of course, values like NA and 999 but they will not be labeled as missing.
Usage
The command line is: freq2.pl [-h] [-c[#-#][#] filename] where: -c#-# indicates starting & ending column numbers of the variable and -c# indicates a single-column variable at column #.
As an example, the command freq2.pl -c210 data.file might produce output like:
(pts/1):~> freq2.pl -c210 data.file Page 1 Frequencies for the values in columns 210-210 in the file "data.file" Value Cumulative Cumulative Value Frequency Percent Frequency Percent ------- --------- ------- ---------- ---------- 0 2214 11.37 2214 11.37 1 1009 5.18 3223 16.55 2 533 2.74 3756 19.28 9 15721 80.72 19477 100.00
Back to Kent's Perl Page Last Modified: Wed Aug 6 16:13:15 EDT 2025