Sentry Page Protection
Data Analysis [13-15]
WEIGHT Statement
The WEIGHT statement allows you to take into account the weight when computing the frequency statistics.
Example
Example
The FOOD data set contains a list of 20 transactions.
Three products are sold:
- Chips
- Pops
- Ham
The data set also includes the quantity sold for each product in each transaction (QTY).
We are interested in counting the total number of item sold for each product.
In order to take into account the quantity sold for each transaction, we will have to add the WEIGHT statement to Proc Freq.
Example
Proc Freq Data=FOOD;
Table Product;
Weight Qty;
Run;
The WEIGHT statement takes into account the quantity sold when computing the frequency statistics:
Let's take a look at the total number of chips sold:
The number total of chips sold are 1+2+4+1+2+1+1 = 12.
Proc Freq compute the correct total in the Results window:
Exercise
Copy and run the LIBRARY data set from the yellow box below:
Copy and run the LIBRARY data set from the yellow box below:
The LIBRARY data set contains a list of books from the library:
- SAS For Dummies
- SAS Base Prep Guide
- SASCrunch Training
The books are distributed across 3 different library location:
- Markham
- Toronto
- North York
The variable N represents the number of copies each library has at their location.
Compute the total number of copies for each book.
Need some help?
HINT:
The number of copies in each library (i.e. N) should be used as the weight factor.
SOLUTION:
Proc Freq Data=Library;
Table Book;
Weight N;
Run;
Fill out my online form.