COMPUTAB Procedure

Example 9.5 Creating an Output Data Set

(View the complete code for this example.)

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


title 'Creating an Output Data Set in PROC COMPUTAB';

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

   ... 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

Creating an Output Data Set in PROC COMPUTAB

divregion_TYPE__NAME_soldrevenuerecdcostPROFITPCTMARG
111JAN1982209025524368-2278-9.348
111FEB2232683021720104672633.456
111MAR1191402021019405-5385-27.751
111QTR15406294068263877-937-1.467
111APR82986016216374-6514-39.783
111MAY1802133067632515005237.233
111JUN1832106012412333872770.761
111QTR244552250353350321721849.149
111JUL19423210991031012900125.121
111AUG153178901641670411867.100


Last updated: June 19, 2025