Creating an Output Data Set
/*--------------------------------------------------------------
SAS Sample Library
Name: ctaex05.sas
Description: Example program from SAS/ETS User's Guide,
The COMPUTAB Procedure
Title: Creating an Output Data Set
Product: SAS/ETS Software
Keys: programmable tabular reports
PROC: COMPUTAB
Notes:
--------------------------------------------------------------*/
data product;
input pcode div region month sold revenue recd cost;
datalines;
1 1 1 1 56 5600 29 2465
1 1 1 2 13 1300 30 2550
1 1 1 3 17 1700 65 5525
2 1 1 1 2 240 50 4900
2 1 1 2 82 9840 17 1666
1 1 1 1 37 3700 75 6375
2 1 1 1 84 10080 28 2744
3 1 1 1 19 2470 73 7884
1 1 1 2 8 800 74 6290
2 1 1 2 71 8520 77 7546
3 1 1 2 49 6370 19 2052
1 1 1 3 16 1600 40 3400
2 1 1 3 46 5520 86 8428
3 1 1 3 40 5200 19 2052
1 1 1 4 17 1700 24 2040
2 1 1 4 29 3480 57 5586
3 1 1 4 36 4680 81 8748
1 1 1 5 62 6200 37 3145
2 1 1 5 21 2520 6 588
3 1 1 5 97 12610 24 2592
1 1 1 6 63 6300 3 255
2 1 1 6 84 10080 99 9702
3 1 1 6 36 4680 22 2376
1 1 1 7 42 4200 14 1190
2 1 1 7 75 9000 6 588
3 1 1 7 77 10010 79 8532
1 1 1 8 56 5600 16 1360
2 1 1 8 32 3840 64 6272
3 1 1 8 65 8450 84 9072
1 1 1 9 22 2200 92 7820
2 1 1 9 3 360 87 8526
3 1 1 9 49 6370 56 6048
1 1 1 10 30 3000 49 4165
2 1 1 10 37 4440 47 4606
3 1 1 10 49 6370 44 4752
1 1 1 11 81 8100 85 7225
2 1 1 11 39 4680 61 5978
3 1 1 11 7 910 79 8532
1 1 1 12 95 9500 74 6290
2 1 1 12 91 10920 50 4900
3 1 1 12 65 8450 41 4428
1 1 2 1 64 6400 60 5100
2 1 2 1 61 7320 67 6566
3 1 2 1 70 9100 65 7020
1 1 2 2 86 8600 50 4250
2 1 2 2 59 7080 51 4998
3 1 2 2 83 10790 6 648
1 1 2 3 74 7400 52 4420
2 1 2 3 27 3240 99 9702
3 1 2 3 77 10010 16 1728
1 1 2 4 22 2200 60 5100
2 1 2 4 70 8400 32 3136
3 1 2 4 5 650 91 9828
1 1 2 5 85 8500 84 7140
2 1 2 5 11 1320 38 3724
3 1 2 5 18 2340 43 4644
1 1 2 6 46 4600 84 7140
2 1 2 6 88 10560 57 5586
3 1 2 6 5 650 47 5076
1 1 2 7 30 3000 22 1870
2 1 2 7 72 8640 79 7742
3 1 2 7 59 7670 52 5616
1 1 2 8 36 3600 41 3485
2 1 2 8 94 11280 34 3332
3 1 2 8 36 4680 2 216
1 1 2 9 55 5500 72 6120
2 1 2 9 84 10080 14 1372
3 1 2 9 43 5590 99 10692
1 1 2 10 64 6400 91 7735
2 1 2 10 46 5520 64 6272
3 1 2 10 32 4160 78 8424
1 1 2 11 55 5500 95 8075
2 1 2 11 6 720 70 6860
3 1 2 11 6 780 15 1620
1 1 2 12 86 8600 50 4250
2 1 2 12 89 10680 73 7154
3 1 2 12 69 8970 35 3780
;
proc sort data=product out=sorted;
by div region;
run;
/* create data set, profit */
proc computab data=sorted notrans out=profit noprint;
by div region;
sumby div;
/* specify order of rows and row titles */
row jan feb mar qtr1;
row apr may jun qtr2;
row jul aug sep qtr3;
row oct nov dec qtr4;
/* specify order of columns and column titles */
columns sold revenue recd cost profit pctmarg;
/* select row for appropriate month */
_row_ = month + ceil( month / 3 ) - 1;
/* calculate quarterly summary rows */
rowcalc:
qtr1 = jan + feb + mar;
qtr2 = apr + may + jun;
qtr3 = jul + aug + sep;
qtr4 = oct + nov + dec;
/* calculate profit columns */
colcalc:
profit = revenue - cost;
if cost > 0 then pctmarg = profit / cost * 100;
run;
/* make a partial listing of the output data set */
options linesize=96;
proc print data=profit(obs=10) noobs;
run;