Wednesday, May 3, 2017

The PROC FREQ(uency) Procedure (SAS)

Proc Frequency or PROC FREQ, is a commonly utilized SAS procedure. To utilize this procedure, the basic form is:

PROC FREQ DATA = <nameofdataset>;
TABLE <columntosummarize>;
RUN;
Ex. DataSetA



PROC FREQ DATA = DataSetA; 
TABLE Gender;
RUN;


The default output that is produced from this code will display:

1. Each unique variable found within the specified column.

2. The number of occurrences of each variable.

3. The total percentage of the occurrence of each variable when weighed against the total number of occurrences.

4. The sum of frequency counts of the variable value, and all other values listed above it in the table.

5. The cumulative frequency of the value divided by the total number of observations.

If you wanted to output the summary results of multiple variable columns, you may specify the option within the Proc Freq procedure.

PROC FREQ DATA = <nameofdataset>;
TABLE <columntosummarize1> <columntosummarize2> <columntosummarize3>;
RUN;

Ex. DataSetA

PROC FREQ DATA = DataSetA;
TABLE Gender HairColor;
RUN;

Additionally, you are given the option to enable various options that change the display of the data summary output.

Some of these options include: 


NOPERCENT - which suppresses cell percentages.



NOCUM - which eliminates the cumulative frequency.



These options are invoked on the second line of the Proc Freq procedure.

PROC FREQ DATA = <nameofdataset>;
TABLE <columntosummarize1> <columntosummarize2> <columntosummarize3> / <option1> <option2> <option3>;
RUN;

Ex. DataSetA

PROC FREQ DATA = DataSetA>;
TABLE HairColor / NOCUM NOPERCENT;
RUN;

Two Way Tables
A two way table is a useful way to sort the frequency of one variable against another. To utilize this procedure, the basic form is:

PROC FREQ DATA = <nameofdataset>;
TABLE <columntosummarize1> * <columntosummarize2>;
RUN;

Ex. DataSetA

PROC FREQ DATA = DataSetA;
TABLE Gender * HairColor;
RUN;


The PROC FREQ procedure is probably the most utilized and most useful SAS feature. Therefore, you should familiarize yourself with the PROC FREQ functionality, and make it a part of your daily SAS usage.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.