The following program creates the SAS data set that this section uses:
data year_sales;
infile 'your-input-file';
input Month $ Quarter $ SalesRep $14. Type $ Units Price;
AmountSold = Units * Price;
run;
Creating Simple Reports
Displaying All the Variables
By default, PROC REPORT uses all of the variables in the data set. The layout of the
report depends on the type of variables in the data set. If the data set contains any
character variables, then PROC REPORT generates a simple detail report that lists the
values of all the variables and the observations in the data set. If the data set contains
only numeric variables, then PROC REPORT sums the value of each variable over all
observations in the data set and produces a one-line summary of the sums. To produce a
detail report for a data set with only numeric values, you have to define the columns in
the report.
By default, PROC REPORT sends your results to the SAS procedure output. The
NOWINDOWS (NOWD) option does not have to be specified. To request that PROC
REPORT open the REPORT window, specify the WINDOWS option. The REPORT
window enables you to modify a report repeatedly and see the modifications
immediately.
The following PROC REPORT step creates the default detail report for the first quarter
sales:
proc report data=year_sales;
where quarter='1';
title1 'TruBlend Coffee Makers, Inc.';
title2 'First Quarter Sales Report';
run;
The WHERE statement specifies a condition that SAS uses to select observations from
the YEAR_SALES data set. Before PROC REPORT builds the report, SAS selectively
processes observations so that the report contains only data for the observations from the
first quarter. For more information about WHERE processing, see “Selecting
Observations” on page 444.
Creating Simple Reports 505
The following detail report shows all the variable values for those observations in
YEAR_SALES that contains first quarter sales data:
Output 29.1 The Default Report When the Data Set Contains Character Values
The following list corresponds to the numbered items in the preceding report:
1
The order of the columns corresponds to the position of the variables in the data set.
2
The top of the report has a title, produced by the TITLE statement.
The following PROC REPORT step produces the default summary report when the
YEAR_SALES data set contains only numeric values:
proc report data=year_sales (keep=Units AmountSold);
title1 'TruBlend Coffee Makers, Inc.';
title2 'Total Yearly Sales';
run;
The KEEP= data set option specifies to process only the numeric variables Units and
AmountSold. PROC REPORT uses these variables to create the report.
506 Chapter 29 Creating Detail and Summary Reports with the REPORT Procedure
The following report displays a one-line summary for the two numeric variables:
Output 29.2 The Default Report When the Data Set Contains Only Numeric Values
PROC REPORT computed the one-line summary for Units and AmountSold by
summing the value of each variable for all the observations in the data set.
Specifying and Ordering the Columns
The first step in constructing a report is to select the columns that you want to appear in
the report. By default, the report contains a column for each variable and the order of the
columns corresponds to the order of the variables in the data set.
You use the COLUMN statement to specify the variables to use in the report and the
arrangement of the columns. In the COLUMN statement, you can list data set variables,
statistics that are calculated by PROC REPORT, or variables that are computed from
other items in the report.
The following program creates a four column sales report for the first quarter:
proc report data=year_sales;
where Quarter='1';
column SalesRep Month Type Units;
title1 'TruBlend Coffee Makers, Inc.';
title2 'First Quarter Sales Report';
run;
The COLUMN statement specifies the order of the items in the report. The first column
lists the values in SalesRep, the second column lists the values in Month, and so on.
Creating Simple Reports 507

Get Step-by-Step Programming with Base SAS 9.4, Second Edition, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.