Chapter Contents

Previous

Next
The PRINT Procedure

Example 5: Summing Numeric Variables with Multiple BY Variables


Procedure features:
BY statement
SUM statement
Other features: SORT procedure
Data set: EXPREV

This example


Program

options nodate pageno=1 linesize=70 pagesize=60;
 Note about code
proc sort data=exprev;
   by region state;
run;
 Note about code
proc print data=exprev n noobs;





 Note about code
   by region state;
   sum expenses revenues;





 Note about code
   label  region='Sales Region';
   format revenues expenses comma10.;
   title 'Revenue and Expense Totals for Each State and Region';
run;


Output
The report uses default column headers (variable names) because neither the SPLIT= nor the LABEL option is used. Nevertheless, the BY line at the top of each section of the report shows the BY variables' labels and their values. The name of a BY variable identifies the subtotals in the report.

PROC PRINT sums Expenses and Revenues for each BY group that contains more than one observation. However, sums are shown only for the BY variables whose values change from one BY group to the next. For example, in the third BY group, where the sales region is Southern and the state is FL, expenses and revenues are summed only for the state because the next BY group is for the same region.

[HTML Output]
 [Listing Output]


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.