The COMPUTAB Procedure |
Program Flow Example |
This example shows how the COMPUTAB procedure processes observations in the program working storage and the COMPUTAB data table (CDT).
Assume you have three years of figures for sales and cost of goods sold (CGS), and you want to determine total sales and cost of goods sold and calculate gross profit and the profit margin.
data example; input year sales cgs; datalines; 1988 83 52 1989 106 85 1990 120 114 ;
proc computab data=example; columns c88 c89 c90 total; rows sales cgs gprofit pctmarg; /* calculate gross profit */ gprofit = sales - cgs; /* select a column */ c88 = year = 1988; c89 = year = 1989; c90 = year = 1990; /* calculate row totals for sales */ /* and cost of goods sold */ col: total = c88 + c89 + c90; /* calculate profit margin */ row: pctmarg = gprofit / cgs * 100; run;
Table 9.3 shows the CDT before any observation is read in. All the columns and rows are defined with the values initialized to 0.
C88 |
C89 |
C90 |
TOTAL |
|
SALES |
0 |
0 |
0 |
0 |
CGS |
0 |
0 |
0 |
0 |
GPROFIT |
0 |
0 |
0 |
0 |
PCTMARG |
0 |
0 |
0 |
0 |
When the first input is read in (year=1988, sales=83, and cgs=52), the input block puts the values for SALES and CGS in the C88 column since year=1988. Also the value for the gross profit for that year (GPROFIT) is calculated as indicated in the following statements:
gprofit = sales-cgs; c88 = year = 1988; c89 = year = 1989; c90 = year = 1990;
Table 9.4 shows the CDT after the first observation is input.
C88 |
C89 |
C90 |
TOTAL |
|
SALES |
83 |
0 |
0 |
0 |
CGS |
52 |
0 |
0 |
0 |
GPROFIT |
31 |
0 |
0 |
0 |
PCTMARG |
0 |
0 |
0 |
0 |
Similarly, the second observation (year=1989, sales=106, cgs=85) is put in the second column, and the GPROFIT is calculated to be 21. The third observation (year=1990, sales=120, cgs=114) is put in the third column, and the GPROFIT is calculated to be 6. Table 9.5 shows the CDT after all observations are input.
C88 |
C89 |
C90 |
TOTAL |
|
SALES |
83 |
106 |
120 |
0 |
CGS |
52 |
85 |
114 |
0 |
GPROFIT |
31 |
21 |
6 |
0 |
PCTMARG |
0 |
0 |
0 |
0 |
After the input block is executed for each observation in the input data set, the first row or column block is processed. In this case, the column block is
col: total = c88 + c89 + c90;
The column block executes for each row, calculating the TOTAL column for each row. Table 9.6 shows the CDT after the column block has executed for the first row (total=83 + 106 + 120). The total sales for the three years is 309.
C88 |
C89 |
C90 |
TOTAL |
|
SALES |
83 |
106 |
120 |
309 |
CGS |
52 |
85 |
114 |
0 |
GPROFIT |
31 |
21 |
6 |
0 |
PCTMARG |
0 |
0 |
0 |
0 |
Table 9.7 shows the CDT after the column block has executed for all rows and the values for total cost of goods sold and total gross profit have been calculated.
C88 |
C89 |
C90 |
TOTAL |
|
SALES |
83 |
106 |
120 |
309 |
CGS |
52 |
85 |
114 |
251 |
GPROFIT |
31 |
21 |
6 |
58 |
PCTMARG |
0 |
0 |
0 |
0 |
After the column block has been executed for all rows, the next block is processed. The row block is
row: pctmarg = gprofit / cgs * 100;
The row block executes for each column, calculating the PCTMARG for each year and the total (TOTAL column) for three years. Table 9.8 shows the CDT after the row block has executed for all columns.
C88 |
C89 |
C90 |
TOTAL |
|
SALES |
83 |
106 |
120 |
309 |
CGS |
52 |
85 |
114 |
251 |
GPROFIT |
31 |
21 |
6 |
58 |
PCTMARG |
59.62 |
24.71 |
5.26 |
23.11 |
Copyright © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.