Paper 141-2010

SAS Global Forum 2010
Foundations and Fundamentals
Paper 141-2010
So You're Still Not Using PROC REPORT. Why Not?
Ray Pass, BJC HealthCare
Daphne Ewing, Auxilium Pharmaceuticals, Inc.
ABSTRACT
Everyone who can spell SAS knows how to use PROC PRINT. Its primary use may be as a development tool to
help in debugging a long multi-step program, or as a simple report generator when all that is really needed is a quick
look at the data, or even a basic low-level finished report. However, if a report generation/information delivery tool
with powerful formatting, summarizing and analysis features is called for, then PROC REPORT is the solution.
PROC REPORT can provide the standard PROC PRINT functionality, but in addition, can easily perform many of the
tasks that you would otherwise have to use the SORT, MEANS, FREQ and TABULATE procedures to accomplish.
PROC REPORT is part of the Base SAS product, can run in both an interactive screen-painting mode or a batch
mode, and should be the basic tool of choice when there is a need to produce powerful and productive reports from
SAS data sets. This paper will present the basics of PROC REPORT (non-interactive mode) through a series of
progressively more sophisticated examples of code and output.
The original main thrust behind PROC REPORT was its interactive WYSIWYG ability, in which reports can be
designed online via screen painting manipulation of actual output. When the desired result is achieved, the design and
structure of the report can be saved as a catalog entry and called up repeatedly for additional runs with new sets of
data. The design can then be modified at any time, and can either be replaced or saved as an additional entry. This is
all done in a Display Manager like environment, and will certainly attract users comfortable with working
interactively. The batch language of PROC REPORT did not at first receive the initial acclaim or publicity that was
afforded the interactive product. In actual fact however, the batch language is every bit as powerful and feature laden
as its online cousin, and is almost a mirror image.
The purpose of this paper is to introduce the batch version of PROC REPORT through a progressive series of
annotated examples. It is not meant to be a full introductory text. There have been a series of stand-alone manuals
published by the SAS Institute for PROC REPORT, and SAS documentation (hardcopy and online versions) from
Release 8 onward includes full coverage of the procedure. In addition, PROC REPORT is fully implemented in the
SAS Output Delivery System (ODS) including a very full and powerful use of styles, There are many excellent
conference papers in existence as well as SAS documentation covering PROC REPORT in ODS. This basic
introduction will not touch upon these features at all.
The data set used throughout this paper is a fictitious survey of the spending habits of 100 college students during
an academic year. The source code in Example-1 describes the data contained in an external file (i.e.
C:\PROCREP\PROCREP.DAT). Although the examples in this paper are PC-based, the REPORT procedure is
identical on all platforms. The example also contains code to create two SAS formats ($SEXFMT. and
$YEARFMT.) which are used throughout the paper along with a simple PROC REPORT statement. Output-1 (see
appendix) displays a portion of the PROC REPORT output from this simple run (the full population is not included in
any of the non-grouped outputs).
data survey;
infile ‘c:\procrep\procrep.dat’;
input @01 fname
$char10.
@12 linit
$char1.
@15 sex
$char1.
@18 acadyear $char1.
@21 gpa
3.1
@27 age
2.
@31 books
4.
@40 food
4.
@49 ent
4. ;
run;
*---------------------------------------------;
1
SAS Global Forum 2010
proc format;
value $sexfmt
Foundations and Fundamentals
‘M’ = ‘MALE’
‘F’ = ‘FEMALE’ ;
value $yearfmt ‘1’
‘2’
‘3’
‘4’
run;
=
=
=
=
‘FRESHMAN’
‘SOPHOMORE’
‘JUNIOR’
‘SENIOR’ ;
*---------------------------------------------;
proc report nowd data=survey;
run;
Example-1
As Output-1 shows, PROC REPORT output in its simplest format is similar to PROC PRINT output. The
NOWD option on the REPORT statement is necessary to tell SAS that this is being run in the batch mode, and not in
the interactive mode (NOWD is an alias for NOWINDOWS.) Example-2 produces the report found in Output-2,
and introduces the basic features of the REPORT Procedure syntax. The first items to note are the HEADLINE and
HEADSKIP options on the PROC REPORT statement. These are two of the many formatting and structural options
available on this statement, and produce the dashed and blank separator lines between the column headers and data.
The COLUMN statement declares the variables to be included in the report structure and the order in which they are
to be processed from left to right. Note that there are two variables listed in the COLUMN statement, NAME and
TOTAL, which are not found in the input data set, but are rather created for use in the report via the COMPUTE
statements described later in the paper. These variables are transient and exist only for the duration of the current
REPORT run; they are not added to the data set named in the REPORT statement. The series of DEFINE statements
is used to assign optional formatting information to the variables. The first two, for FNAME and LINIT, instruct
REPORT not to print these two variables, via a NOPRINT option. They must be included in the COLUMN statement
because the NAME variable is computed from the values of these two variables. They are therefore part of the data
set being REPORTed, but are not included in the output. The order in which these variables appear in the COLUMN
statement is important here, as NAME must be preceded by the variables it is computed from.
proc report nowd data=survey headline headskip;
column fname linit name sex acadyear gpa age books food ent total;
define
define
define
define
define
define
define
define
define
define
define
fname
linit
sex
acadyear
gpa
age
books
food
ent
name
total
/
/
/
/
/
/
/
/
/
/
/
display
display
display
display
analysis
analysis
analysis
analysis
analysis
computed
computed
noprint;
noprint;
format=$sexfmt.
'ACADEMIC/YEAR' format=$yearfmt.
format=3.1
format=3.
'$-BOOKS'
format=dollar6.
'$-FOOD'
format=dollar6.
'$-ENTERTAIN'
format=dollar6.
'$-TOTAL'
format=dollar6.
width=6;
width=9;
width=3;
width=3;
width=7;
width=6;
width=11;
width=10;
width=7;
compute name /char length=10;
name = trim(fname) || ' ' || linit || '.';
endcomp;
compute total;
total = sum(books.sum, food.sum, ent.sum);
endcomp;
run;
Example-2
PROC REPORT supports six different types of output variables with different uses: DISPLAY, ANALYSIS,
COMPUTED, ORDER, GROUP, and ACROSS. In this example, the DEFINE statements declare FNAME, LINIT,
SEX and ACADYEAR as DISPLAY variables, GPA, AGE, BOOKS, FOOD and ENT as ANALYSIS variables, and
NAME and TOTAL as COMPUTED variables. By default, character variables are DISPLAY and numeric variables
are ANALYSIS variables. It is good practice, however, to include these designations anyway; it makes for ease of
reading and modification of the code. For DISPLAY and ANALYSIS, all values in the input data set are displayed in
2
SAS Global Forum 2010
Foundations and Fundamentals
the output. The FORMAT and WIDTH options declare output value formats and column widths, and the quoted
strings create the column headers. Note that ACADYEAR has a split header (two header lines separated by a split
character). The default split character is the forward slash (“/”), but this can be changed with a SPLIT= option on the
REPORT statement if a slash is a valid part of a header or data value. Note also that the WIDTHs must be adequate
to contain both the data and the headers (e.g. „$-ENTERTAIN‟ needs a WIDTH=11).
The variables NAME and TOTAL were included in the COLUMN statement, and declared in the DEFINE
statements as COMPUTED variables. These variables are created in 'compute blocks', each block beginning with a
COMPUTE statement and ending with an ENDCOMP statement. The compute blocks contain DATA step statements
which create the COMPUTED variables. Options on the COMPUTE statement which create NAME declare it to be a
CHARACTER variable with a LENGTH of 10. When referring to an ANALYSIS variable in a compute block, you
must use “compound name” syntax (e.g. BOOKS.SUM) to name both the variable and the statistic associated with it,
delimiting them with a dot (“.”).
Output-2 displays a useful, formatted, one line per observation report as created with the code in Example-2.
Much can be done however in terms of ordering the data for presentation. Example-3 contains the code which
produces the categorized and sorted data displayed in Output-3. Here the data is ordered by ACADYEAR and SEX.
The first change to note from the code in the previous listing is that the order of variables in the COLUMN
statement has been changed. Variables used to order the data, referred to as ORDER variables, must be processed
before (to the left of) any DISPLAY variables. This makes intuitive sense as you look at the output, and is backed up
by rigid syntactical placement rules. The DEFINE statements declare ACADYEAR and SEX to be ORDER variables.
This is what actually creates the sorted display. Note that only the first unique value of each of these variables is
displayed. Using ORDER variables eliminates the need for a prior sorting of the data set with PROC SORT. Note
that although the sequenced order of variables is critical in the COLUMN statement, it is of no concern in the series of
DEFINE statements. The DEFINE statement for ACADYEAR also includes the ORDER= option, which in this case
is assigned as INTERNAL. This instructs the REPORT procedure to sort (and display) the observations by their
INTERNAL values (1, 2, 3, 4) rather than their formatted values (FRESHMAN, JUNIOR, SENIOR, SOPHOMORE).
Other possible presentation orders (FORMATTED, DATA, FREQUENCY) are available as they are in the MEANS,
FREQ, and TABULATE procedures. NOTE: The default display order for PROC REPORT is FORMATTED,
unlike all the other SAS procedures which use INTERNAL as the default.
proc report nowd data=survey headline headskip;
column acadyear sex fname linit name gpa age books food ent total;
define
define
define
define
fname
linit
sex
acadyear
/
/
/
/
display
display
order
order
noprint;
noprint;
define
define
define
define
define
define
define
gpa
age
books
food
ent
name
total
/
/
/
/
/
/
/
analysis
analysis
analysis
analysis
analysis
computed
computed '$-TOTAL'
format=$sexfmt.
'ACADEMIC/YEAR' format=$yearfmt.
order=internal;
format=3.1
format=3.
'$-BOOKS'
format=dollar6.
'$-FOOD'
format=dollar6.
'$-ENTERTAIN'
format=dollar6.
format=dollar6.
compute name / char length=10;
name = trim(fname) || ' ' || linit || '.';
endcomp;
compute total;
total = sum(books.sum, food.sum, ent.sum);
endcomp;
run;
Example-3
3
width=6;
width=9
width=3;
width=3;
width=7;
width=6;
width=11;
width=10;
width=7;
SAS Global Forum 2010
Foundations and Fundamentals
The next feature of PROC REPORT to be discussed is the ability to collapse (group) observations sharing the
same value of any variable or set of variables, and to display summary statistics for each subset of observations. This
is done in Example-4 by changing ACADYEAR and SEX to GROUP variables, with the results displayed in
Output-4.
proc report nowd data=survey headline headskip;
column acadyear sex gpa age books food ent total;
define sex
/ group
define acadyear / group
define
define
define
define
define
define
gpa
age
books
food
ent
total
/
/
/
/
/
/
analysis
analysis
analysis
analysis
analysis
computed
format=$sexfmt.
'ACADEMIC/YEAR' format=$yearfmt.
order=internal;
format=3.1
format=3.
'$-BOOKS'
format=dollar6.
'$-FOOD'
format=dollar7.
'$-ENTERTAIN'
format=dollar7.
'$-TOTAL'
format=dollar7.
width=6;
width=9
width=3;
width=3;
width=7;
width=7;
width=11;
width=7;
compute total;
total = sum(books.sum, food.sum, ent.sum);
endcomp;
run;
Example-4
FNAME, LINIT and NAME can not be meaningfully summarized within other (GROUP) variables, and are therefore
removed from the COLUMN and DEFINE statements, and also from the summarized report output. Although they
can be changed to ORDER or GROUP variables, they can not remain in the design as DISPLAY variables with
GROUP variables to their left; and changing them to ORDER or GROUP variables in this example would not provide
useful information. Note that the NAME compute block must also be removed. The remaining variables, including
the COMPUTED variable TOTAL, are summarized over each ACADYEAR-SEX combination. The resulting sum is
displayed in each cell of the report.
Although the SUM statistic might carry some meaning with the financial variables (BOOKS, FOOD, ENT, and
TOTAL), a MEAN value would probably be more desirable. For GPA and AGE however, the SUM statistic is
meaningless and a MEAN value is absolutely needed. Example-5 accomplishes these goals by using the 'alias'
feature of the REPORT procedure as well as demonstrating the use of different statistics for ANALYSIS variables.
This example also demonstrates the powerful ability of the procedure to produce summary break lines, as well as
compound column-spanning headers. A few more goodies are demonstrated in the example as well. The resulting
much enhanced display is found in Output-5.
title1 'PROC REPORT - SAMPLE SUMMARY REPORT';
title2 '--------- ACADEMIC SURVEY ---------';
title3;
*--------------------------------------------;
proc report nowd data=survey split='\';
column acadyear sex gpa age ('-ANNUAL AMOUNT SPENT ON-'
('-BOOKS-'
books books=booksm)
('-FOOD-'
food food =foodm)
('-ENTERTAIN-' ent
ent =entm)
('-TOTAL-'
total totalm));
define sex
/ group
define acadyear / group
define
define
define
define
define
define
define
gpa
age
books
booksm
food
foodm
ent
/
/
/
/
/
/
/
analysis
analysis
analysis
analysis
analysis
analysis
analysis
'SEX\--'
'ACADEMIC\YEAR\--'
order=internal;
'MEAN\GPA\--'
'MEAN\AGE\--'
'TOTAL\--'
'MEAN\--'
'TOTAL\--'
'MEAN\--'
'TOTAL\--'
4
format=$sexfmt. width=6;
format=$yearfmt. width=9
format=3.1 mean
format=3. mean
format=dollar7.
format=dollar4.
format=dollar7.
format=dollar4.
format=dollar7.
width=4;
width=4;
width=7
width=4
width=7
width=4
width=7
sum;
mean;
sum;
mean;
sum;
SAS Global Forum 2010
define entm
define total
define totalm
Foundations and Fundamentals
/ analysis 'MEAN\--'
/ computed 'TOTAL\--'
/ computed 'MEAN\--'
format=dollar4.
format=dollar8.
format=dollar7.
width=4 mean;
width=8;
width=7;
compute total;
total = sum(books.sum, food.sum, ent.sum);
endcomp;
compute totalm;
totalm = sum(bookm, foodm, entm);
endcomp;
break after acadyear / ol ul skip summarize suppress;
rbreak after / dol dul skip summarize;
run;
Example-5
Much is happening in this example. The HEADLINE and HEADSKIP options are removed from the REPORT
statement in lieu of another method of creating header underlines. Each DEFINE statement now contains an
additional final segment in its title option, namely '\--'. These two dashes will automatically expand to the width of the
column, yielding a broken, but perhaps more pleasing set of column header underlines (the keyword is 'perhaps' as it
is somewhat subjective, but at least the alternative is available). Notice that the SPLIT='\' option is used (any
character can be defined as a line splitting delimiter). When this technique is used, all variables should be given this
type of title for uniformity of display.
The next major change is the enhanced COLUMN statement. Aliases are created for the BOOKS, FOOD and
ENT variables, namely BOOKM, FOODM and ENTM. This is done so that the information for each of these
variables can be presented in two different manners via separate DEFINE statements for each variable and its alias.
Each variable is displayed first as a SUM (this is the default presentation for all ANALYSIS variables) and then as a
MEAN, by including these statistics in the appropriate DEFINE statements. New variables are not being created;
each variable with an alias is merely being displayed multiple times.
The COLUMN statement now also contains column-spanning headers. These can be simple (a header which spans
multiple columns) or compound as in this example. A column spanning header is created by including a quoted string
in parentheses preceding the columns it is to span. In the header, the initial and final characters can be extended to the
total width of the set of columns it spans. In our example, the uppermost header, '-ANNUAL AMOUNT SPENT ON' spans all the displayed variables, and the next level down headers, „-BOOKS-„, etc. each span one variable and its
alias.
The DEFINE statements for the ANALYSIS variables and their aliases, and for the COMPUTED variables
TOTAL and TOTALM are enhanced in various ways. REPORT is now instructed to display each of the GROUP and
ANALYSIS variables as both a MEAN and a SUM (if no statistic is presented, the default SUM is used). In addition,
WIDTHs and FORMATs are changed judiciously (trial and error) to accommodate the new headers and data
displayed. A new COMPUTED variable TOTALM is now calculated from the aliases of the components making up
TOTAL. Since they are MEAN values, the new variable TOTALM will reflect MEAN values as well. Note that
aliases do not use the compound dot notation.
Another enhancement to the new display is the addition of summary break lines to the report. The BREAK
command inserts a break line AFTER each new value of ACADYEAR (the keyword BEFORE can also be used to
place break lines before grouped variables). Each new line has a summary statistic (SUMMARIZE) with an overline
(OL), an underline (UL) and a blank line (SKIP) before the next printed line. The RBREAK command instructs
REPORT to print a break line AFTER the entire report (BEFORE is also available), with double over and
underlining (DOL, DUL) and overall summary statistics (SUMMARIZE). Each of the BREAK commands also uses
the SUPPRESS option to prevent printing BREAK information (values, under- and overlining) under the GROUP
variable columns (ACADYEAR, SEX). The last enhancements to the code in Example-5 is the addition of TITLE
statements. These statements are standard SAS syntax, and are not saved with the REPORT definition if it is stored as
a catalog entry.
5
SAS Global Forum 2010
Foundations and Fundamentals
Output-5 presents a useful display of grouped information. PROC REPORT also allows other types of useful
formatted output, both grouped and non-grouped. Example-6 contains code used to display the telephone-bookcolumn style display found in Output-6.
In Example-6, the REPORT statement contains three new options which instruct the procedure to display the
data in three repeating 'snaking' sets of variables (PANELS) with a pagesize (PS) of 50 lines, and 10 spaces between
each panel (PSPACE). Only NAME, ACADYEAR and AGE are printed (note that FNAME and LINIT must be
included in the COLUMN statement for processing, but are not printed via NOPRINT).
title1 'PROC REPORT - SAMPLE COLUMNAR REPORT';
title2 '---------- ACADEMIC SURVEY ---------';
title3;
*--------------------------------------------;
proc report nowd data=survey headline headskip panels=3 ps=50 pspace=10;
column fname linit name acadyear gpa;
define
define
define
define
define
fname
linit
acadyear
gpa
name
/
/
/
/
/
display noprint;
display noprint;
display 'ACADEMIC/YEAR' format=$yearfmt. width=9;
analysis
format=3.1
width=3;
computed
width=10;
compute name / char length=10;
name = trim(fname)||' '||linit||'.';
endcomp;
run;
Example-6
Example-7 also uses PANELS to display its data, but now uses the FLOW option to achieve a different
presentation style. The FLOW option instructs the procedure to wrap the value of a character variable within its
column width. In this example, the COMPUTEd character variable BLOCK is constructed to include the defined split
character „\‟ between each of its components. As the FLOW option honors split characters, the effect is a wrapping to
a new line for each component in BLOCK. The FLOW option can easily be used to generate name and address
listings. Note that all the components that make up BLOCK are required in the COLUMN statement, but they are all
NOPRINTed. Note also that an artificially large number of PANELS (99) is stated. This technique allows the
procedure to determine how many PANELS to produce based on the linesize used.
title1 'PROC REPORT - SAMPLE FLOW REPORT';
title2 '-------- ACADEMIC SURVEY -------';
title3;
*----------------------------------------;
proc report nowd data=survey split='\' panels=99
ps=50
;
column fname linit acadyear age sex gpa block;
define
define
define
define
define
define
define
fname
linit
acadyear
age
sex
gpa
block
/
/
/
/
/
/
/
display
display
display
display
display
display
computed
noprint;
noprint;
noprint;
noprint;
noprint;
noprint;
flow width=20 '';
compute block / char length=100;
block = 'name: '||trim(fname)||' '||linit||'.'
||'\YEAR: '||put(acadyear,$yearfmt.)
||'\ AGE: '||put(age,2.)
||'\ SEX: '||put(sex,$sexfmt.)
||'\ GPA: '||put(gpa,3.1)
||'\\';
endcomp;
run;
Example-7
6
SAS Global Forum 2010
Foundations and Fundamentals
Example-8 also contains code for a non-grouped data display as shown in Output-8. In this example, the
WRAP option in the REPORT statement causes the values for all variables in an observation to be printed in a linewrap fashion before printing of the next observation is begun.
title1 'PROC REPORT - SAMPLE WRAPPED REPORT';
title2 '--------- ACADEMIC SURVEY ---------';
title3;
*-------------------------------------------;
data survey2;
set survey;
obsno = _n_;
run;
*-------------------------------------------;
proc report nowd data=survey2 headline headskip named wrap ls=70;
column obsno fname linit name acadyear age sex gpa books food ent total;
define
define
define
define
define
define
define
define
define
define
define
define
obsno
fname
linit
sex
acadyear
gpa
age
books
food
ent
name
total
/
/
/
/
/
/
/
/
/
/
/
/
order
display
display
display
display
analysis
analysis
analysis
analysis
analysis
computed
computed
noprint;
noprint;
noprint;
format=$sexfmt.
format=$yearfmt.
format=3.1
format=3.
'$-BOOKS'
format=dollar6.
'$-FOOD'
format=dollar6.
'$-ENTERTAIN' format=dollar6.
'YEAR'
'$-TOTAL'
format=dollar6.
width=6;
width=9;
width=3;
width=3;
width=6;
width=6 spacing=3;
width=6 spacing=3;
width=10;
width=7 spacing=3;
compute name /char length=10;
name = trim(fname)||' '||linit||'.';
endcomp;
compute total;
total = sum(books.sum, food.sum, ent.sum);
endcomp;
break after obsno / skip;
run;
Example-8
The NAMED option causes each variable to be preceded by its header (variable names would be used if no headers
were presented) followed by “=“. The LS or Linesize option causes REPORT to restrict horizontal printing to 70
columns. Some of the DEFINE statements use a SPACING option to manipulate the number of blank spaces printed
before each value. This was done to create the quasi columnar alignment which makes for easier reading. Each
observation is also followed by a blank line before the next one is started. The REPORT procedure does not at
present provide for double-spacing, so it had to be tricked into it. This was done with the aid of some pre-processing
of the data set before the REPORT procedure was called. Data set SURVEY2 was created by SET'ing SURVEY, and
then creating a new variable, OBSNO, by assigning it the value of the observation counter (_N_), an automatic system
variable provided by the SAS system. The REPORT procedure was then run against data set SURVEY2. In the
REPORT code, OBSNO is DEFINE'd as an ORDER variable, and a BREAK statement is used with the SKIP option
to add a blank line after each new value of OBSNO. As each value of OBSNO (_N_) is unique, the effect is to skip a
line after each new observation printed.
The final example is shown in Output-9, and was created with the code found in Example-9. This example
demonstrates the last variable type allowed in PROC REPORT. The variables included in the example are
ACADYEAR, SEX, GPA, where SEX is DEFINE'd as an ACROSS variable. This causes its values to be grouped
like a GROUP variable, but displayed horizontally rather than vertically. The next enhancement is in the format of
the COLUMN statement. The order of processing the variable is: ACADYEAR SEX GPA. The “,” in the statement
after SEX instructs REPORT to print the summary values of the ANALYSIS variable GPA under the unique values of
the ACROSS variable SEX (if no statistics were included for GPA, the frequency of observations in each cell would
7
SAS Global Forum 2010
Foundations and Fundamentals
be printed). This syntax allows PROC REPORT to display its data in a simple PROC TABULATE like manner, and
demonstrates more of the power of the REPORT procedure.
title1 'PROC REPORT - SAMPLE ACROSS REPORT';
title2 '--------- ACADEMIC SURVEY --------';
title3;
*-----------------------------------------------;
proc report nowd data=survey headline headskip out=out_ex;
column acadyear sex,gpa;
define sex
/ across
format=$sexfmt. width=6;
define acadyear / group
'ACADEMIC/YEAR' format=$yearfmt. width=9;
define gpa
/ analysis
format=3.1
width=6
run;
*-----------------------------------------------;
title1 "CONTENTS OF PROC REPORT OUTPUT DATA SET";
title2 "----- PRODUCED WITH 'OUT=' OPTION -----";
title3;
*-----------------------------------------------;
proc print data=out_ex;
run;
mean;
Example-9
The final addition in Example-9 is the use of the output data set option, OUT=output data set, in the REPORT
statement. This instructs the procedure to produce an output SAS data set containing one observation for each output
line of data in the REPORT output. If the report contains summary (BREAK) lines, then the name of the BREAK
variable is contained in a new variable called “_BREAK_”. If there are no BREAKs, the value of “_BREAK_” is
missing. We include a simple PROC PRINT here (we are not REPORT bigots) to display the contents of the output
data set OUT_EX. Whenever an ACROSS variable is used, PROC REPORT uses a “_Cn_” notation to name each
column. In this example, the two values of the ACROSS variable SEX (“FEMALE” and “MALE”) are represented
in OUT_EX as _C2_ and _C3_ respectively. Getting used to the “_Cn_” notation is a chore, but well worth it.
Although other procedures can produce output data sets of summary values, using ACROSS variables with output
data sets can be used to produce summarized cross-tabular output data.
There are many additional features in the REPORT procedure which have not been included in this paper due to
the desire to keep this on a very basic introductory level, but which add significantly to the utility of the procedure.
One example is the ability to include strings of literal text in the body of the output, and the ability to conditionally
include whole segments of output based on values of data set or COMPUTED variables. Other new features are being
developed and will be included in future releases of the SAS System base product, and its accompanying
documentation.
CONCLUSION
The REPORT procedure is a powerful and productive tool in the SAS user's report writing arsenal, and should be
fully examined and exploited. It provides a much expanded realm of utility over the PRINT procedure alone. PROC
REPORT can do much of the work of PROC SORT, PROC MEANS and a fair amount of PROC TABULATE. It is
by no means a reporting panacea, and should never be used to the total exclusion of other procedures. It can, and
should however be used appropriately and cooperatively with other SAS System tools to provide a powerful synergy.
So if you‟re still not using PROC REPORT, or have no intention to at least investigate it, once again we can only
ask, Why Not?
8
SAS Global Forum 2010
Foundations and Fundamentals
REFERENCES
SAS is a registered trademark of the SAS Institute Inc., Cary, NC, USA.
AUTHORS
The authors of this paper can be contacted as follows:
Ray Pass, BJC HealthCare
Voice: (314) 362-1172
E-mail: [email protected]
Daphne Ewing, Auxilium Pharmaceuticals, Inc.
Voice: (215) 740-6503
E-mail: [email protected]
9
SAS Global Forum 2010
Foundations and Fundamentals
The SAS System
FNAME
DORY
GERALD
HARRY
REGGIE
VALERIE
ANTHONY
GEORGE
TOM
CAROL
EDWARD
KATHY
BILL
CARMEN
DONNA
FRANK
JOAN
LEON
ROSE
TOM
ALLAN
BETTY
DENNIS
EVELYN
L
I
N
I
T
A
A
A
A
A
B
B
B
C
C
C
D
D
D
D
D
D
D
D
E
E
E
E
S
E
X
F
M
M
F
F
M
M
M
F
M
F
M
F
F
M
F
M
F
M
M
F
M
F
A
C
A
D
Y
E
A
R
3
3
4
3
3
1
3
2
4
1
4
3
4
1
4
2
1
2
2
3
2
3
2
GPA
4.0
3.5
3.6
3.6
3.2
2.0
2.5
3.8
1.6
2.9
2.5
3.8
3.9
3.2
3.6
2.0
2.9
3.6
3.6
3.5
3.6
2.8
3.2
AGE
20
20
19
20
20
16
21
19
21
18
21
18
18
19
21
27
18
18
18
21
20
19
19
BOOKS
381
265
544
100
532
425
522
215
344
451
544
244
522
652
675
680
201
205
406
345
222
541
265
FOOD
945
655
855
841
756
855
752
625
1200
466
842
810
1022
802
841
789
755
866
485
455
755
480
855
ENT
1144
687
478
654
250
965
425
622
602
2101
874
620
587
785
254
855
400
100
544
852
962
221
452
Output- 1
The SAS System
ACADEMIC
NAME
SEX
YEAR
GPA AGE $-BOOKS $-FOOD $-ENTERTAIN $-TOTAL
-----------------------------------------------------------------------------DORY A.
GERALD A.
HARRY A.
REGGIE A.
VALERIE A.
ANTHONY B.
GEORGE B.
TOM B.
CAROL C.
EDWARD C.
KATHY C.
BILL D.
CARMEN D.
DONNA D.
FRANK D.
JOAN D.
LEON D.
ROSE D.
TOM D.
ALLAN E.
BETTY E.
DENNIS E.
EVELYN E.
JONAH E.
FEMALE
MALE
MALE
FEMALE
FEMALE
MALE
MALE
MALE
FEMALE
MALE
FEMALE
MALE
FEMALE
FEMALE
MALE
FEMALE
MALE
FEMALE
MALE
MALE
FEMALE
MALE
FEMALE
MALE
JUNIOR
JUNIOR
SENIOR
JUNIOR
JUNIOR
FRESHMAN
JUNIOR
SOPHOMORE
SENIOR
FRESHMAN
SENIOR
JUNIOR
SENIOR
FRESHMAN
SENIOR
SOPHOMORE
FRESHMAN
SOPHOMORE
SOPHOMORE
JUNIOR
SOPHOMORE
JUNIOR
SOPHOMORE
SENIOR
4.0
3.5
3.6
3.6
3.2
2.0
2.5
3.8
1.6
2.9
2.5
3.8
3.9
3.2
3.6
2.0
2.9
3.6
3.6
3.5
3.6
2.8
3.2
3.2
20
20
19
20
20
16
21
19
21
18
21
18
18
19
21
27
18
18
18
21
20
19
19
17
$381
$265
$544
$100
$532
$425
$522
$215
$344
$451
$544
$244
$522
$652
$675
$680
$201
$205
$406
$345
$222
$541
$265
$569
Output-2
10
$945
$655
$855
$841
$756
$855
$752
$625
$1,200
$466
$842
$810
$1,022
$802
$841
$789
$755
$866
$485
$455
$755
$480
$855
$785
$1,144
$687
$478
$654
$250
$965
$425
$622
$602
$2,101
$874
$620
$587
$785
$254
$855
$400
$100
$544
$852
$962
$221
$452
$457
$2,470
$1,607
$1,877
$1,595
$1,538
$2,245
$1,699
$1,462
$2,146
$3,018
$2,260
$1,674
$2,131
$2,239
$1,770
$2,324
$1,356
$1,171
$1,435
$1,652
$1,939
$1,242
$1,572
$1,811
SAS Global Forum 2010
Foundations and Fundamentals
The SAS System
ACADEMIC
YEAR
SEX
NAME
GPA AGE $-BOOKS $-FOOD $-ENTERTAIN $-TOTAL
-----------------------------------------------------------------------------FRESHMAN
FEMALE
MALE
SOPHOMORE
FEMALE
MALE
DONNA D.
LILLY E.
JANE K.
JACKIE M.
JOAN O.
DEBBIE R.
SALLY R.
ERICA S.
ARLENE T.
ANTHONY B.
EDWARD C.
LEON D.
SAM E.
JOHN F.
JOEL H.
MIKE J.
FRANK L.
GEORGE L.
JIM R.
ROBERT S.
MANNY V.
JOAN D.
ROSE D.
BETTY E.
EVELYN E.
CHERYL F.
CINDY F.
LAURIE F.
CONNIE K.
MARIE K.
ELLEN T.
MILLY T.
ROBIN Y.
DINA Z.
TOM B.
TOM D.
3.2
3.6
2.9
2.1
2.8
3.8
3.8
4.0
3.5
2.0
2.9
2.9
3.4
3.8
2.5
3.2
3.5
2.8
3.7
3.8
3.4
2.0
3.6
3.6
3.2
3.8
3.7
3.2
2.9
3.2
3.0
4.0
3.5
3.5
3.8
3.6
19
18
18
16
18
18
18
18
18
16
18
18
18
20
24
19
19
18
38
17
34
27
18
20
19
19
19
19
19
19
19
28
20
18
19
18
$652
$489
$402
$402
$306
$432
$524
$560
$512
$425
$451
$201
$894
$512
$524
$254
$478
$490
$452
$500
$325
$680
$205
$222
$265
$245
$318
$345
$156
$523
$241
$325
$345
$255
$215
$406
$802
$966
$1,300
$1,200
$522
$230
$600
$455
$466
$855
$466
$755
$688
$741
$987
$522
$946
$954
$866
$547
$862
$789
$866
$755
$855
$577
$622
$844
$544
$684
$622
$876
$788
$655
$625
$485
$785
$954
$541
$454
$777
$556
$400
$201
$412
$965
$2,101
$400
$865
$905
$950
$656
$125
$795
$555
$220
$544
$855
$100
$962
$452
$622
$455
$650
$999
$787
$956
$557
$454
$445
$622
$544
$2,239
$2,409
$2,243
$2,056
$1,605
$1,218
$1,524
$1,216
$1,390
$2,245
$3,018
$1,356
$2,447
$2,158
$2,461
$1,432
$1,549
$2,239
$1,873
$1,267
$1,731
$2,324
$1,171
$1,939
$1,572
$1,444
$1,395
$1,839
$1,699
$1,994
$1,819
$1,758
$1,587
$1,355
$1,462
$1,435
Output-3
The SAS System
ACADEMIC
YEAR
SEX
GPA AGE $-BOOKS
$-FOOD
$-ENTERTAIN
$-TOTAL
--------------------------------------------------------------------FRESHMAN
SOPHOMORE
JUNIOR
SENIOR
FEMALE
MALE
FEMALE
MALE
FEMALE
MALE
FEMALE
MALE
30
38
43
57
45
61
21
26
161
259
264
335
285
393
143
207
$4,279
$5,506
$4,125
$5,115
$5,985
$7,185
$3,031
$5,164
$6,541
$9,189
$9,477
$12,034
$10,820
$15,963
$6,281
$6,801
Output-4
11
$5,080
$9,081
$8,294
$10,979
$8,122
$9,860
$4,696
$5,007
$15,900
$23,776
$21,896
$28,128
$24,927
$33,008
$14,008
$16,972
SAS Global Forum 2010
Foundations and Fundamentals
PROC REPORT – SAMPLE SUMMARY REPORT
--------- ACADEMIC SURVEY --------ACADEMIC
YEAR
--------FRESHMAN
SEX
-----FEMALE
MALE
MEAN
GPA
---3.3
3.2
---3.2
----
MEAN
AGE
---18
22
---20
----
--------------------ANNUAL AMOUNT SPENT ON-----------------------BOOKS---- ----FOOD----- --ENTERTAIN-- ------TOTAL-----TOTAL MEAN
TOTAL MEAN
TOTAL MEAN
TOTAL
MEAN
------- ---- ------- ---- ------- ---- -------- ------$4,279 $475
$6,541 $727
$5,080 $564
$15,900
$1,767
$5,506 $459
$9,189 $766
$9,081 $757
$23,776
$1,981
------- ---- ------- ---- ------- ---- -------- ------$9,785 $466 $15,730 $749 $14,161 $674
$39,676
$1,889
------- ---- ------- ---- ------- ---- -------- -------
SOPHOMORE
FEMALE
MALE
3.3
3.3
---3.3
----
20
20
---20
----
$4,125
$5,115
------$9,240
-------
$317
$301
---$308
----
$9,477
$12,034
------$21,511
-------
$729
$708
---$717
----
$8,294
$10,979
------$19,273
-------
$638
$646
---$642
----
$21,896
$28,128
-------$50,024
--------
$1,684
$1,655
------$1,667
-------
JUNIOR
FEMALE
MALE
3.2
3.2
---3.2
----
20
21
---21
----
$5,985
$7,185
------$13,170
-------
$428
$378
---$399
----
$10,820
$15,963
------$26,783
-------
$773
$840
---$812
----
$8,122
$9,860
------$17,982
-------
$580
$519
---$545
----
$24,927
$33,008
-------$57,935
--------
$1,781
$1,737
------$1,756
-------
SENIOR
FEMALE
MALE
3.0
2.9
---2.0
----
20
23
---22
----
$3,031
$5,164
------$8,195
-------
$433
$574
---$512
----
$6,281
$6,801
------$13,082
-------
$897
$756
---$818
----
$4,696
$5,007
------$9,703
-------
$671
$556
---$606
----
$14,008
$16,972
-------$30,980
--------
$2,001
$1,886
------$1,936
-------
====
3.2
====
====
20
====
=======
$40,390
=======
====
$404
====
=======
$77,106
=======
====
$771
====
=======
$61,119
=======
====
$611
====
========
$178,615
========
=======
$1,786
=======
Output-5
12
SAS Global Forum 2010
Foundations and Fundamentals
PROC REPORT – SAMPLE COLUMNAR REPORT
---------- ACADEMIC SURVEY --------ACADEMIC
NAME
YEAR
GPA
-------------------------DORY A.
JUNIOR
4.0
GERALD A.
JUNIOR
3.5
HARRY A.
SENIOR
3.6
REGGIE A.
JUNIOR
3.6
VALERIE A. JUNIOR
3.2
ANTHONY B. FRESHMAN
2.0
GEORGE B.
JUNIOR
2.5
TOM B.
SOPHOMORE 3.8
CAROL C.
SENIOR
1.6
EDWARD C.
FRESHMAN
2.9
KATHY C.
SENIOR
2.5
BILL D.
JUNIOR
3.8
CARMEN D.
SENIOR
3.9
DONNA D.
FRESHMAN
3.2
FRANK D.
SENIOR
3.6
JOAN D.
SOPHOMORE 2.0
LEON D.
FRESHMAN
2.9
ROSE D.
SOPHOMORE 3.6
TOM D.
SOPHOMORE 3.6
ALLAN E.
JUNIOR
3.5
BETTY E.
SOPHOMORE 3.6
DENNIS E.
JUNIOR
2.8
EVELYN E.
SOPHOMORE 3.2
JONAH E.
SENIOR
3.2
LILLY E.
FRESHMAN
3.6
MARIA E.
JUNIOR
3.4
SAM E.
FRESHMAN
3.4
WILLIAM E. SOPHOMORE 3.7
CHERYL F.
SOPHOMORE 3.8
ACADEMIC
NAME
YEAR
GPA
-------------------------SALLY I.
JUNIOR
3.5
WILLIAM I. SOPHOMORE 3.6
ALAN J.
JUNIOR
3.4
MIKE J.
FRESHMAN
3.2
CONNIE K.
SOPHOMORE 2.9
DAVID K.
SOPHOMORE 3.8
EILEEN K.
SENIOR
3.0
JANE K.
FRESHMAN
2.9
JOSE K.
SOPHOMORE 3.5
MARIE K.
SOPHOMORE 3.2
PETER K.
SOPHOMORE 3.6
TERRY K.
JUNIOR
4.0
FRANK L.
FRESHMAN
3.5
GEORGE L.
FRESHMAN
2.8
SHEILA L.
SENIOR
4.0
STEVE L.
SOPHOMORE 3.5
DAN M.
JUNIOR
1.6
DANIEL M.
SOPHOMORE 2.3
JACKIE M.
FRESHMAN
2.1
LOU M.
JUNIOR
2.0
FRED O.
SENIOR
2.5
JOAN O.
FRESHMAN
2.8
HARRIET P. JUNIOR
3.0
PAUL P.
SOPHOMORE 2.6
LARRY Q.
JUNIOR
3.7
CARL R.
JUNIOR
3.6
CYNTHIA R. JUNIOR
3.0
DEBBIE R.
FRESHMAN
3.8
HENRY R.
JUNIOR
3.8
ACADEMIC
NAME
YEAR
GPA
-------------------------ARLENE T.
FRESHMAN
3.5
BEN T.
JUNIOR
3.2
ELLEN T.
SOPHOMORE 3.0
MILLY T.
SOPHOMORE 4.0
WILL T.
SENIOR
2.9
ANNA V.
JUNIOR
2.3
MANNY V.
FRESHMAN
3.4
DAVID W.
JUNIOR
2.5
PAUL W.
SENIOR
3.0
AL X.
SOPHOMORE 2.5
ROBIN Y.
SOPHOMORE 3.5
SAM Y.
SOPHOMORE 4.0
TONY Y.
SENIOR
2.0
DINA Z.
SOPHOMORE 3.5
Output-6
PROC REPORT - SAMPLE FLOW REPORT
-------- ACADEMIC SURVEY ------NAME:
YEAR:
AGE:
SEX:
GPA:
DORY A.
JUNIOR
20
FEMALE
4.0
NAME:
YEAR:
AGE:
SEX:
GPA:
TOM B.
SOPHOMORE
19
MALE
3.8
NAME:
YEAR:
AGE:
SEX:
GPA:
FRANK D.
SENIOR
21
MALE
3.6
NAME:
YEAR:
AGE:
SEX:
GPA:
DENNIS E.
JUNIOR
19
MALE
2.8
NAME:
YEAR:
AGE:
SEX:
GPA:
GERALD A.
JUNIOR
20
MALE
3.5
NAME:
YEAR:
AGE:
SEX:
GPA:
CAROL C.
SENIOR
21
FEMALE
1.6
NAME:
YEAR:
AGE:
SEX:
GPA:
JOAN D.
SOPHOMORE
27
FEMALE
2.0
NAME:
YEAR:
AGE:
SEX:
GPA:
EVELYN E.
SOPHOMORE
19
FEMALE
3.2
NAME:
YEAR:
AGE:
SEX:
GPA:
HARRY A.
SENIOR
19
MALE
3.6
NAME:
YEAR:
AGE:
SEX:
GPA:
EDWARD C.
FRESHMAN
18
MALE
2.9
NAME:
YEAR:
AGE:
SEX:
GPA:
LEON D.
FRESHMAN
18
MALE
2.9
NAME:
YEAR:
AGE:
SEX:
GPA:
JONAH E.
SENIOR
17
MALE
3.2
NAME:
YEAR:
AGE:
SEX:
GPA:
REGGIE A.
JUNIOR
20
FEMALE
3.6
NAME:
YEAR:
AGE:
SEX:
GPA:
KATHY C.
SENIOR
21
FEMALE
2.5
NAME:
YEAR:
AGE:
SEX:
GPA:
ROSE D.
SOPHOMORE
18
FEMALE
3.6
NAME:
YEAR:
AGE:
SEX:
GPA:
LILLY E.
FRESHMAN
18
FEMALE
3.6
NAME:
YEAR:
AGE:
SEX:
GPA:
VALERIE A.
JUNIOR
20
FEMALE
3.2
NAME:
YEAR:
AGE:
SEX:
GPA:
BILL D.
JUNIOR
18
MALE
3.8
NAME:
YEAR:
AGE:
SEX:
GPA:
TOM D.
SOPHOMORE
18
MALE
3.6
NAME:
YEAR:
AGE:
SEX:
GPA:
MARIA E.
JUNIOR
20
FEMALE
3.4
Output-7
13
SAS Global Forum 2010
Foundations and Fundamentals
PROC REPORT - SAMPLE WRAPPED REPORT
--------- ACADEMIC SURVEY -----------------------------------------------------------------------------NAME=DORY A.
$-BOOKS= $381
YEAR=JUNIOR
$-FOOD= $945
AGE= 20 SEX=FEMALE
$-ENTERTAIN=$1,144
GPA=4.0
$-TOTAL= $2,470
NAME=GERALD A.
$-BOOKS= $265
YEAR=JUNIOR
$-FOOD= $655
AGE= 20 SEX=MALE
$-ENTERTAIN= $687
GPA=3.5
$-TOTAL= $1,607
NAME=HARRY A.
$-BOOKS= $544
YEAR=SENIOR
$-FOOD= $855
AGE= 19 SEX=MALE
$-ENTERTAIN= $478
GPA=3.6
$-TOTAL= $1,877
NAME=REGGIE A.
$-BOOKS= $100
YEAR=JUNIOR
$-FOOD= $841
AGE= 20 SEX=FEMALE
$-ENTERTAIN= $654
GPA=3.6
$-TOTAL= $1,595
NAME=VALERIE A.
$-BOOKS= $532
YEAR=JUNIOR
$-FOOD= $756
AGE= 20 SEX=FEMALE
$-ENTERTAIN= $250
GPA=3.2
$-TOTAL= $1,538
NAME=ANTHONY B.
$-BOOKS= $425
YEAR=FRESHMAN
$-FOOD= $855
AGE= 16 SEX=MALE
$-ENTERTAIN= $965
GPA=2.0
$-TOTAL= $2,245
NAME=GEORGE B.
$-BOOKS= $522
YEAR=JUNIOR
$-FOOD= $752
AGE= 21 SEX=MALE
$-ENTERTAIN= $425
GPA=2.5
$-TOTAL= $1,699
NAME=TOM B.
$-BOOKS= $215
YEAR=SOPHOMORE
$-FOOD= $625
AGE= 19 SEX=MALE
$-ENTERTAIN= $622
GPA=3.8
$-TOTAL= $1,462
NAME=CAROL C.
$-BOOKS= $344
YEAR=SENIOR
$-FOOD=$1,200
AGE= 21 SEX=FEMALE
$-ENTERTAIN= $602
GPA=1.6
$-TOTAL= $2,146
NAME=EDWARD C.
$-BOOKS= $451
YEAR=FRESHMAN
$-FOOD= $466
AGE= 18 SEX=MALE
$-ENTERTAIN=$2,101
GPA=2.9
$-TOTAL= $3,018
NAME=KATHY C.
$-BOOKS= $544
YEAR=SENIOR
$-FOOD= $842
AGE= 21 SEX=FEMALE
$-ENTERTAIN= $874
GPA=2.5
$-TOTAL= $2,260
NAME=BILL D.
$-BOOKS= $244
YEAR=JUNIOR
$-FOOD= $810
AGE= 18 SEX=MALE
$-ENTERTAIN= $620
GPA=3.8
$-TOTAL= $1,674
NAME=CARMEN D.
$-BOOKS= $522
YEAR=SENIOR
$-FOOD=$1,022
AGE= 18 SEX=FEMALE
$-ENTERTAIN= $587
GPA=3.9
$-TOTAL= $2,131
NAME=DONNA D.
$-BOOKS= $652
YEAR=FRESHMAN
$-FOOD= $802
AGE= 19 SEX=FEMALE
$-ENTERTAIN= $785
GPA=3.2
$-TOTAL= $2,239
NAME=FRANK D.
$-BOOKS= $675
YEAR=SENIOR
$-FOOD= $841
AGE= 21 SEX=MALE
$-ENTERTAIN= $254
GPA=3.6
$-TOTAL= $1,770
Output-8
PROC REPORT-SAMPLE ACROSS REPORT
------- ACADEMIC SURVEY -------SEX
ACADEMIC
FEMALE
MALE
YEAR
GPA
GPA
------------------------FRESHMAN
SOPHOMORE
JUNIOR
SENIOR
_
3.3
3.3
3.2
3.0
3.2
3.3
3.2
2.9
CONTENTS OF PROC REPORT OUTPUT DATA SET
----- PRODUCED WITH 'OUT=' OPTION ----OBS
ACADYEAR
_C2_
_C3_
1
2
3
4
1
2
3
4
3.30000
3.32308
3.24286
3.00000
3.15833
3.34706
3.22632
2.90000
Output-9b
Output-9a
14
_BREAK_