Procedure features: |
PROC
PRINT statement options:
|
BY statement |
SUM statement |
|
Other features: |
ODS CSVALL statement |
SORT procedure |
TITLE statement
|
SAS system options:
|
|
Data set: |
EXPREV
|
This example
-
sums expenses and
revenues for each region and for all regions
-
shows the number of observations in each BY group and in the whole
report
-
creates a customized title, containing the name of the region.
This title replaces the default BY line for each BY group
-
creates a CSV file.
![Note about code](../../../../common/63294/HTML/default/images/snbut.gif) |
options nodate pageno=1 linesize=80 pagesize=40 obs=10 nobyline; |
![Note about code](../../../../common/63294/HTML/default/images/snbut.gif) |
proc sort data=exprev;
by sale_type;
run; |
![Note about code](../../../../common/63294/HTML/default/images/snbut.gif) |
proc print data=exprev noobs label sumlabel
n='Number of observations for the order type: '
'Number of observations for the data set: '; |
![Note about code](../../../../common/63294/HTML/default/images/snbut.gif) |
var country order_date quantity price; |
![Note about code](../../../../common/63294/HTML/default/images/snbut.gif) |
label sale_type='Sale Type'
price='Total Retail Price* in USD'
country='Country' order_date='Date' quantity='Quantity'; |
![Note about code](../../../../common/63294/HTML/default/images/snbut.gif) |
sum price quantity;
by sale_type; |
![Note about code](../../../../common/63294/HTML/default/images/snbut.gif) |
format price dollar7.2; |
![Note about code](../../../../common/63294/HTML/default/images/snbut.gif) |
title 'Retail and Quantity Totals for #byval(sale_type) Sales';
run; |
![Note about code](../../../../common/63294/HTML/default/images/snbut.gif) |
options byline; |
Retail and Quantity Totals for Catalog Sales 1
Total
Retail
Price*
Country Date Quantity in USD
Puerto Rico 1/1/08 14 $51.20
Aruba 1/1/08 30 $123.70
Bahamas 1/1/08 8 $113.40
Bermuda 1/1/08 7 $41.00
British Virgin Islands 1/2/08 11 $40.20
Canada 1/2/08 100 $11.80
---------------------- -------- -------
Sale Type 170 $381.30
Number of observations for the order type: 6
Retail and Quantity Totals for In Store Sales 2
Total
Retail
Price*
Country Date Quantity in USD
Virgin Islands (U.S.) 1/1/08 25 $31.10
Belize 1/2/08 2 $146.40
Cayman Islands 1/2/08 20 $71.00
--------------------- -------- -------
Sale Type 47 $248.50
Number of observations for the order type: 3
Retail and Quantity Totals for Internet Sales 3
Total
Retail
Price*
Country Date Quantity in USD
Antarctica 1/1/08 2 $92.60
======== =======
219 $722.40
Number of observations for the order type: 1
Number of observations for the data set: 10
options nodate pageno=1 linesize=80 pagesize=40 obs=10 nobyline;
![Note about code](../../../../common/63294/HTML/default/images/snbut.gif) |
ods csvall file='your_file.csv'; |
proc sort data=exprev;
by sale_type;
run;
proc print data=exprev noobs label sumlabel
n='Number of observations for the order type: '
'Number of observations for the data set: ';
var country order_date quantity price;
label price='Total Retail Price* in USD'
country='Country' order_date='Date' quantity='Quantity';
sum price quantity;
by sale_type;
format price dollar7.2;
title 'Retail and Quantity Totals for #byval(sale_type) Sales';
run;
options byline;
![Note about code](../../../../common/63294/HTML/default/images/snbut.gif) |
ods csvall close; |
Summing Numeric Variables with One BY Group: CSV Output Viewed with a Microsoft Excel
![[Summing Numeric Variables with One BY Group: CSV Output Viewed with a Microsoft Excel]](images/procprintcsvoutput.gif)
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.