Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

SAS frequency distribution


May 27, 2021 SAS


Table of contents


The frequency distribution is a table that shows the frequency of the data points in the data set. Each entry in the table contains the frequency or count of values within a specific group or interval, and in this way, the table summarizes the distribution of values in the sample.

SAS provides a process called PROC FREQ to calculate the frequency distribution of data points in the data set.

Grammar

The basic syntax for calculating frequency distribution in SAS is:

PROC FREQ DATA = Dataset ;
TABLES Variable_1 ;
BY Variable_2 ;

The following is a description of the parameters used:

  • Dataset is the name of the dataset.
  • Variables_1 is the variable name of the dataset whose frequency distribution needs to be calculated.
  • Variables_2 is a variable that classifys frequency distribution results.

Single variable frequency distribution

We can use PROC FREQ to determine the frequency distribution of individual variables. I n this case, the result shows the frequency of each value of the variable. T he results also show the percentage distribution, cumulative frequency, and cumulative percentage.

Cases

In the following example, we find the frequency distribution of the variable horsepower of a dataset called CARS1, created from the library SASHELP.CARS. W e can see that the results fall into two categories. O ne for every car.

PROC SQL;
create table CARS1 as
SELECT make,model,type,invoice,horsepower,length,weight
 FROM 
SASHELP.CARS
WHERE make in ('Audi','BMW')
;
RUN;

proc FREQ data=CARS1 ;
tables horsepower; 
by make;
run;

When we execute the code above, we get the following results:

SAS frequency distribution

Multivarivation frequency distribution

We can find the frequency distribution of multiple variables and compose them into all possible combinations.

Cases

In the following example, we calculate the frequency distribution of automobile manufacturing grouped by car type and the frequency distribution of each type of car grouped by each manufacturing group.

proc FREQ data=CARS1 ;
tables make type; 
run;

When we execute the code above, we get the following results:

SAS frequency distribution

Frequency distribution and weight

Using the weight option, we can calculate the frequency distribution that is biased by the weight of the variable. H ere, the value of the variable is taken as the number of observations, not the count of the values.

Cases

In the following example, we calculate the frequency distribution of the variables make and type, assigned to the weight of horsepower.

proc FREQ data=CARS1 ;
tables make type; 
weight horsepower;
run;

When we execute the code above, we get the following results:

SAS frequency distribution