Producing a Formatted Summary Report - SAS Programming

In this example,you use PROC MEANS to do much of the work that is often done by using extensive data manipulation in a DATA step,such as accumulating sums and counting missing values.You use several of the OUTPUT options in PROC MEANS to create an output summary data set that is then further formatted in a subsequent DATA step.This data set is then processed by PROC PRINT to produce the final report.

The fictitious data in this example were collected as part of a fund drive and then stored in SAS data set FUND.Each observation represents a letter mailed out to a resident asking for a contribution.The variables contained in FUND are NAME, TOWNSHIP, and AMOUNT.When the value for AMOUNT is missing, no donation was made by that person. Here is the SAS data set FUND:

Producing a Formatted Summary Report

You want to produce a report showing the following information for each township: the number of letters mailed, the total number of donations received,the total amount received, the average amount received per donation, and the average amount received per letter mailed.Sound difficult? Not if you use PROC MEANS.Here is the code:

Example

OPTIONS LS*72 NONUMBER NODATE?
PROC MEANS DATA=FUND NOPRINT NWAY;
CLASS TOWNSHIP?
VAR AMOUNT;
OUTPUT OUT =SUMMARY
N =RETURN£D 0
NMISS*NOTJ*ETN
SUM =TOTAL;
RUN;
DATA REPORT;
SET SUMMARY?
MAILED*RETURNED+NOTJ*ETN? 0
*Alternative: MAILED=_FREQ_ ;
PER_RETN=TOTAL/RETURNED? ©
PER~MAIL»TOTAL/MAILED; O
LABEL MAILED ='LETTERS MAILED' @
RETURNED*'NUMBER OF DONATIONS'
TOTAL ='TOTAL DONATION'
PER_RETN='MEAN DONATION*
PER~MAIL»'MEAN DONATION PER LETTER MAILED';
RUN;
0
PROC PRINT DATA*REPORT LABEL DOUBLE;
TITLE 'Fund Drive Summary Report';
ID TOWNSHIP;
VAR MAILED RETURNED TOTAL PERJIETN PERJ1AIL;
FORMAT MAILED RETURNED COMMAS?
TOTAL DOLLAR?.
PER^RETN PERJiAIL DOLLARS.?
RUN;

The statistics N, NMISS, and SUM in the PROC MEANS code provide you with some of the finished quantities you are looking for.You output N as RETURNED O and eventually label it as "NUMBER OF DONATIONS," © and output SUM as TOTAL and then label that as "TOTAL DONATION." NMISS is output as NOT_RETN. In the DATA step, you calculate the rest of the variables you need.

You add N (RETURNED) and NMISS (NOT_RETN) to get MAILED (total number of units mailed per township) © and label it "LETTERS MAILED"©. SUM (TOTAL) is divided by RETURNED (number of donations) © to get PER_RETN ("MEAN DONATION"),and by MAILED (number of units mailed) 0 to get PER_MAIL ("MEAN DONATION PER LETTER MAILED") to complete the data you need for the report.The LABEL option of PROC PRINT 0 instructs the system to use the labels connected to the variables for column headings instead of the variable names, and the DOUBLE option double spaces the report.The final listing from the program is shown here:

Output from Example- Producing a Formatted Summary Report

Output from Example - Producing a Formatted Summary Report

As you can see, this complete formatted summary report was generated with very little effort, using PROC MEANS as the centerpiece of the program.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics