The COMPUTAB Procedure

Example 9.5 Creating an Output Data Set

This example uses data and reports similar to those in Example 9.3 to illustrate the creation of an output data set.

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

   ... more lines ...   

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;

Because the NOTRANS option is specified, column names become variables in the data set. REGION has missing values in the output data set for observations associated with consolidation tables. The output data set PROFIT, in conjunction with the option NOPRINT, illustrates how you can use the computational features of PROC COMPUTAB for creating additional rows and columns as in a spreadsheet without producing a report. Output 9.5.1 shows a partial listing of the output data set PROFIT.

Output 9.5.1: Partial Listing of the PROFIT Data Set

XYZ Development Corporation
Corporate Headquarters: New York, NY
Profit Summary
 

div region _TYPE_ _NAME_ sold revenue recd cost PROFIT PCTMARG
1 1 1 JAN 198 22090 255 24368 -2278 -9.348
1 1 1 FEB 223 26830 217 20104 6726 33.456
1 1 1 MAR 119 14020 210 19405 -5385 -27.751
1 1 1 QTR1 540 62940 682 63877 -937 -1.467
1 1 1 APR 82 9860 162 16374 -6514 -39.783
1 1 1 MAY 180 21330 67 6325 15005 237.233
1 1 1 JUN 183 21060 124 12333 8727 70.761
1 1 1 QTR2 445 52250 353 35032 17218 49.149
1 1 1 JUL 194 23210 99 10310 12900 125.121
1 1 1 AUG 153 17890 164 16704 1186 7.100