Frequency count with SAS

This is a trick I picked up at work today. I wanted to see how many times a particular transaction executed within one second for all today’s transactions. There’s a timestamp on each transaction, so all I had to do was execute the FREQ proc in SAS to get the count for each second.

The FREQ Procedure
Cumulative    Cumulative
DATEYY    Frequency     Percent     Frequency      Percent
---------------------------------------------------------------
429010110           2        0.00             2         0.00
429010111           1        0.00             3         0.00
429010112           1        0.00             4         0.00
429010113           1        0.00             5         0.01
429010114           1        0.00             6         0.01
429010116           2        0.00             8         0.01
429010118           5        0.01            13         0.01

But, I also wanted to see what the max count was for each second in the log. So, I added an OUT option to the FREQ proc, like this:

PROC FREQ DATA=SYSUT1 NOPRINT;
TABLE DATEYY / OUT=SYSUT2;

PROC FORMAT;
VALUE _RNG  1-5 = ‘(1-5)’
6-10 = ‘(6-10)’
11-50 = ‘(11-50)’
51-99 = ‘(51-99)’
100-999 = ‘(>100)’;

PROC FREQ DATA=SYSUT2;
TABLE COUNT;
FORMAT COUNT _RNG. ;

PROC MEANS N MIN MAX;
VAR COUNT;

The OUT option writes to a SAS (not an external) file. The column that holds the frequency count is called COUNT. The FORMAT proc lets me select a range of values to assign to COUNT.

Then, another FREQ execution gives me a report of COUNT by the ranges in the FORMAT proc. Proc MEANS just gives me the max COUNT value for the whole process.

The FREQ Procedure                  �
Frequency Count                   �
Cumulative    Cumulative
COUNT    Frequency     Percent     Frequency      Percent
------------------------------------------------------------
(1-5)         45498       95.41         45498        95.41
(6-10)         2138        4.48         47636        99.89
(11-50)          53        0.11         47689       100.00

The MEANS Procedure        �
Analysis Variable : COUNT Frequency Count
N         Minimum         Maximum
-------------------------------------
47689       1.0000000      16.0000000
-------------------------------------

Comments are closed.