Proc Report
Proc Report
Proc Report
Applications Development
Paper 079-2008
INTRODUCTION
The syntax of PROC REPORT is different from all the other procedures and many of us found the manual less than helpful in learning its unique statements. Most of us turned to a colleague and asked him to explain PROC REPORT. We got a brief introduction and a set of sample code that weve been modifying ever since. This paper will give you the same thinga simple introduction and lots of sample code to enhance as needed.
SYNTAX
Next, let me describe PROC REPORTs syntax. The COLUMN statement is used to list each report column. Each column, in turn, has a DEFINE statement that describes how that column is created and formatted. You use the TITLE statement to specify the title at the top of each page. PROC REPORT DATA=datasetname <options>; TITLE title text; COLUMN variable list and column specifications; DEFINE column / define type and column attributes; DEFINE column / define type and column attributes; ... RUN;
Applications Development
County Scott Scott Scott Scott Scott Scott Scott Adams Adams Adams Adams Adams Adams Adams
Variety Merlot Chardonnay Zinfandel Merlot Merlot Chardonnay Zinfandel Merlot Chardonnay Zinfandel Chardonnay Merlot Chardonnay Zinfandel
If you compare Simple Report to Raw Data created in Step 1, you will notice a few differences. Simple Report doesnt have an OBS column the variables are listed in their order in the column statement the column headers are the labels not the variable names the column headers are adjusted to the column width, not the other way around By the way, nofs is used to turn off the procedures interactive features.
Applications Development
Scott
Notice how cty, the ordered column, doesnt repeat in each row, only when it changes.
52200
Scott
52388
52423
You probably noticed that the GROUP define type isnt very helpfulunless it is used with the ANALYSIS define type.
Applications Development
Applications Development
Scott
52388 52423
There are many options for the BREAK and RBREAK statements: OL overline DOL UL underline DUL summarize summarize each group skip suppress dont repeat the break variable on the summary line
Applications Development
Report with Row Sums (Computed Type) --------- Grape Variety ---------County Zip Merlot Chardonnay Zinfandel Name Code Revenue Revenue Revenue Total ------------------------------------------------------------Adams 52199 52200 233.03 385.51 ---------618.54 122.89 241.30 ---------364.19 ========== 982.73 185.22 322.24 ---------507.46 78.22 156.61 ---------234.83 ========== 742.29 95.84 151.10 ---------246.94 15.40 35.50 ---------50.90 ========== 297.84 514.09 858.85 ---------1,372.94 216.51 433.41 ---------649.92 ========== 2,022.86
Scott
52388 52423
If you don't know how many columns your ACROSS define type will create, just use the maximum possible _C#_ variablesthe extras don't hurt. A COMPUTE block can contain, more or less, everything allowed in a DATA step including macro variables and %include. And remember, you can also reference any report item from within the block.
CONCLUSION
See how far youve comejust one step at a time. Now you can build most of the reports you need using just these few elements. PROC REPORT does have more advanced features--use the manual to fill in those finer points. I suggest looking at the COLUMN statement. It has several capabilities that I havent mentioned. The COMPUTE block is very powerful. But use it with caution. Often your programs will be easier to understand and maintain if you make your calculations in a DATA step before PROC REPORT rather than getting fancy in a COMPUTE block.
RECOMMENDED READING
Carpenter, Arthur. PROC REPORT Basics: Getting Started with the Primary Statements" http://www.caloxy.com/papers/65_HOW07.pdf.
Carpenter, Arthur. 2007. Carpenters Complete Guide to the SAS REPORT Procedure. Cary, NC: SAS Institute Inc.
CONTACT INFORMATION
Your comments and questions are valued and encouraged. I can be reached at: David Lewandowski Thomson Healthcare 1007 Church Street Suite 700 Evanston, IL 60201 dave.lewandowski@thomson.com www.thomsonhealthcare.com SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. indicates USA registration. Other brand and product names are trademarks of their respective companies.