Return to Homepage

Goto the Tip of the Month Archive

Other interesting pages ...
LinkedIn Profile
SAS Cheat Sheet
Useful SAS Code
Full SAS Example
Basic Statistics
Contact Information

SAS Tip of the Month
December 2013
(for SAS and WPS)

This month it is a quick look at PROC FREQ and just trying to get what we need.

First, lets look at some data:

   data student;
      length name $20 sex $1 age 8 major $20;
      input name $ sex $ age major $;
   cards;
   Alexandra F 15 Science
   Bailey    F 16 Mathematics
   Blake     M 18 Art
   Caroline  F 16 Sports
   Dominic   M 13 Literature
   Jose      M 17 Art
   Justin    M 18 Literature
   Melanie   F 15 Mathematics
   Oliver    M 15 Sports
   Sydney    F 14 Science
   ;
   run;

A request has come in to get a count of the number of students by sex and major, so lets use PROC FREQ with the following call:

   proc freq data=student;
      tables sex*major;
   run;

which results in the following output:

                          The FREQ Procedure

                        Table of sex by major

    sex       major

    Frequency|
    Percent  |
    Row Pct  |
    Col Pct  |Art     |Literatu|Mathemat|Science |Sports  |  Total
             |        |re      |ics     |        |        |
    ---------+--------+--------+--------+--------+--------+
    F        |      0 |      0 |      2 |      2 |      1 |      5
             |   0.00 |   0.00 |  20.00 |  20.00 |  10.00 |  50.00
             |   0.00 |   0.00 |  40.00 |  40.00 |  20.00 |
             |   0.00 |   0.00 | 100.00 | 100.00 |  50.00 |
    ---------+--------+--------+--------+--------+--------+
    M        |      2 |      2 |      0 |      0 |      1 |      5
             |  20.00 |  20.00 |   0.00 |   0.00 |  10.00 |  50.00
             |  40.00 |  40.00 |   0.00 |   0.00 |  20.00 |
             | 100.00 | 100.00 |   0.00 |   0.00 |  50.00 |
    ---------+--------+--------+--------+--------+--------+
    Total           2        2        2        2        2       10
                20.00    20.00    20.00    20.00    20.00   100.00

As can be seen the information displayed includes frequency, and cell, row and column percentages, but all we really want is the frequency!

There are serveral options with the table statement that control the statistics produced, including:

NOCUM
Suppresses cumulative sums (one-way tables only)
NOPERCENT
Suppresses percentages and cumulative percentages
NOROW
Suppresses row sums and percentages (two-way or higher tables)
NOCOL
Suppresses column sums and percentages (two-way or higher tables)
NOFREQ
Suppresses frequency count display (rarely used)

Now lets run the the PROC FREQ with some options to control the display:

   proc freq data=student;
      tables sex*major /nopercent norow nocol;
   run;

and this results in the following output:

                          The FREQ Procedure

                        Table of sex by major

    sex       major

    Frequency|Art     |Literatu|Mathemat|Science |Sports  |  Total
             |        |re      |ics     |        |        |
    ---------+--------+--------+--------+--------+--------+
    F        |      0 |      0 |      2 |      2 |      1 |      5
    ---------+--------+--------+--------+--------+--------+
    M        |      2 |      2 |      0 |      0 |      1 |      5
    ---------+--------+--------+--------+--------+--------+
    Total           2        2        2        2        2       10

This just gives us counts which is what we want!

Hope you have a safe and happy December. See you next year!

________________________________
Updated December 2, 2013