![]() Chapter Contents |
![]() Previous |
![]() Next |
| The REPORT Procedure |
To understand the process of building a report, you must understand the difference between report variables and DATA step variables. Variables that appear only in one or more compute blocks are DATA step variables. Variables that appear in one or more columns of the report are report variables. A report variable may or may not appear in a compute block.
| Sequence of Events |
Note: Because of the way PROC REPORT builds a report, you can
![[cautionend]](../common/images/cautend.gif)
For more information about using compute blocks, see Using Compute Blocks and the discussion of the COMPUTE statement COMPUTE Statement .
The summary line that PROC REPORT constructs at this point is preliminary. If no compute block is attached to the break, the preliminary summary line becomes the final summary line. However, if a compute block is attached to the break, the statements in the compute block can alter the values in the preliminary summary line.
PROC REPORT prints the summary line only if you summarize numeric variables
in the break.
libname proclib 'SAS-data-library';
options nodate pageno=1 linesize=64
pagesize=60 fmtsearch=(proclib);
proc report data=grocery nowindows;
column sector manager sales;
define sector / group format=$sctrfmt.;
define sales / analysis sum
format=dollar9.2;
define manager / group format=$mgrfmt.;
break after sector / summarize skip ol;
rbreak after / summarize dol dul;
compute after;
sector='Total:';
endcomp;
run;
Three Different Meanings of Sales.sum
The SAS System 1
Sector Manager Sales
Northeast Alomar $786.00 |
Here Sales.sum has three different meanings:
![[cautionend]](../common/images/cautend.gif)
| Building a Report That Uses Groups and a Report Summary |
At the end of the report a break summarizes the
statistics and computed
variables in the report and assigns to Sector the value of
TOTALS:.
The following statements produce Report with Groups and a Report Summary . The user-defined formats that are used are created by a PROC FORMAT step .
libname proclib 'SAS-data-library';
options nodate pageno=1 linesize=64
pagesize=60 fmtsearch=(proclib);
proc report data=grocery headline headskip;
column sector department sales Profit N;
define sector / group format=$sctrfmt.;
define department / group format=$deptfmt.;
define sales / analysis sum
format=dollar9.2;
define profit / computed format=dollar9.2;
compute profit;
if department='np1' or department='np2'
then profit=0.4*sales.sum;
else profit=0.25*sales.sum;
endcomp;
rbreak after / dol dul summarize;
compute after;
sector='TOTALS:';
endcomp;
where sector contains 'n';
title 'Report for Northeast and Northwest Sectors';
run;
Report with Groups and a Report Summary
Report for Northeast and Northwest Sectors 1
Sector Department Sales Profit N
------------------------------------------------------
Northeast Canned $840.00 $336.00 2
Meat/Dairy $490.00 $122.50 2
Paper $290.00 $116.00 2
Produce $211.00 $52.75 2
Northwest Canned $1,070.00 $428.00 3
Meat/Dairy $1,055.00 $263.75 3
Paper $150.00 $60.00 3
Produce $179.00 $44.75 3
========= ========= ========= =========
TOTALS: $4,285.00 $1,071.25 20
========= ========= ========= ========= |
A description of how PROC REPORT builds this report follows:
First Detail Row with Values Initialized
First Detail Row with Values Filled in from Left to Right
np1 or np2)
return a profit of 40%; perishable items (which have a value of p1 or p2) return a profit of
25%.
if department='np1' or department='np2'
then profit=0.4*sales.sum;
else profit=0.25*sales.sum;
The row now looks like A Computed Variable Added to the First Detail Row .
![[cautionend]](../common/images/cautend.gif)
A Computed Variable Added to the First Detail Row
sector='TOTALS:';
This statement replaces the value of Sector, which in the summary line
is missing by default, with the word
TOTALS:. After PROC REPORT
executes the statement, it modifies the summary line to reflect this change
to the value of Sector. The final version of the summary line appears in Final Summary Line .
| Building a Report That Uses DATA Step Variables |
Because all compute blocks share the current values of all variables, you can initialize DATA step variables at a break at the beginning of the report or at a break before a break variable. This report initializes the DATA step variable Sctrtot at a break before Sector.
If no compute block is attached to a break, the preliminary summary
line becomes the final summary line. ![[cautionend]](../common/images/cautend.gif)
The report in Report with DATA Step Variables contains five columns:
At the beginning of the report, a customized report summary tells what the sales for all stores are. At a break before each group of observations for a department, a default summary summarizes the data for that sector. At the end of each group a break inserts a blank line.
The following statements produce Report with DATA Step Variables . The user-defined formats that are used are created by a PROC FORMAT step .
Note: Calculations of the percentages do not
multiply their results
by 100 because PROC REPORT prints them with the PERCENT. format. ![[cautionend]](../common/images/cautend.gif)
libname proclib 'SAS-data-library';
options nodate pageno=1 linesize=64
pagesize=60 fmtsearch=(proclib);
proc report data=grocery noheader nowindows;
column sector department sales
Sctrpct sales=Salespct;
define sector / 'Sector' group
format=$sctrfmt.;
define department / group format=$deptfmt.;
define sales / analysis sum
format=dollar9.2 ;
define sctrpct / computed
format=percent9.2 ;
define salespct / pctsum format=percent9.2;
compute before;
line ' ';
line @16 'Total for all stores is '
sales.sum dollar9.2;
line ' ';
line @29 'Sum of' @40 'Percent'
@51 'Percent of';
line @6 'Sector' @17 'Department'
@29 'Sales'
@40 'of Sector' @51 'All Stores';
line @6 55*'=';
line ' ';
endcomp;
break before sector / summarize ul;
compute before sector;
sctrtot=sales.sum;
sctrpct=sales.sum/sctrtot;
endcomp;
compute sctrpct;
sctrpct=sales.sum/sctrtot;
endcomp;
break after sector/skip;
where sector contains 'n';
title 'Report for Northeast and Northwest Sectors';
run;
Report with DATA Step Variables
Report for Northeast and Northwest Sectors 1
Total for all stores is $4,285.00
Sum of Percent Percent of
Sector Department Sales of Sector All Stores
=======================================================
Northeast $1,831.00 100.00% 42.73%
--------- --------- --------- ---------
Northeast Canned $840.00 45.88% 19.60%
Meat/Dairy $490.00 26.76% 11.44%
Paper $290.00 15.84% 6.77%
Produce $211.00 11.52% 4.92%
Northwest $2,454.00 100.00% 57.27%
--------- --------- --------- ---------
Northwest Canned $1,070.00 43.60% 24.97%
Meat/Dairy $1,055.00 42.99% 24.62%
Paper $150.00 6.11% 3.50%
Produce $179.00 7.29% 4.18%
|
A description of how PROC REPORT builds this report follows:
Initialized DATA Step Variables
At this break, Sales.sum is the sales for all stores, and Sales.pctsum is the percentage those sales represent for all stores (100%). PROC REPORT takes the values for these statistics from the temporary file that it created at the beginning of the report-building process.
The value for Sctrpct comes from executing the statements in the corresponding compute block. Because the value of Sctrtot is missing, PROC REPORT cannot calculate a value for Sctrpct. Therefore, in the preliminary summary line (which is not printed in this case), this variable also has a missing value (see Preliminary and Final Summary Line for the Break at the Beginning of the Report ).
The statements in the COMPUTE BEFORE block do not alter any variables. Therefore, the final summary line is the same as the preliminary summary line.
Note: The COMPUTE BEFORE statement creates a break at the beginning
of the report. You do not need to use an RBREAK statement. ![[cautionend]](../common/images/cautend.gif)
Preliminary and Final Summary Line for the Break at the Beginning of the Report
The value for Sctrpct comes from executing the statements in the corresponding compute blocks. Because the value of Sctrtot is still missing, PROC REPORT cannot calculate a value for Sctrpct. Therefore, in the preliminary summary line, Sctrpct has a missing value (see Preliminary Summary Line for the Break before the First Group of Observations ).
Preliminary Summary Line for the Break before the First Group of Observations
![[cautionend]](../common/images/cautend.gif)
Final Summary Line for the Break before the First Group of Observations
First Detail Row with Initialized Values
Filling in Values from Left to Right
sctrpct=sales.sum/sctrtot;
The row now looks like First Detail Row with the First Computed Variable Added .
First Detail Row with the First Computed Variable Added
Northeast to
Northwest. PROC REPORT constructs a preliminary summary
line for the break before this group of observations. As at the beginning
of any row, PROC REPORT initializes all report variables to missing but retains
the value of the DATA step variable. Next, it completes the preliminary summary
line with the appropriate values for the break variable (Sector), the statistics
(Sales.sum and Sales.pctsum), and the computed variable (Sctrpct). At this
break, Sales.sum is the sales for the Northwest sector. Because the COMPUTE
BEFORE Sector block has not yet executed, the value of Sctrtot is still $1,831.00,
the value for the Northeast sector. Thus, the value that PROC REPORT calculates
for Sctrpct in this preliminary summary line is incorrect (see Preliminary Summary Line for the Break before the Second Group of Observations ).
The statements in the compute block for this break calculate the correct value
(see the following step).
Preliminary Summary Line for the Break before the Second Group of Observations
![[cautionend]](../common/images/cautend.gif)
Final Summary Line for the Break before the Second Group of Observations
Because the program contains a BREAK BEFORE statement with the SUMMARIZE option, PROC REPORT writes the final summary line to the report. The UL option in the BREAK statement underlines the summary line.
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.