Previous Page | Next Page

The COMPUTAB Procedure

Column Selection

The following discussion assumes that the NOTRANS option has not been specified. When NOTRANS is specified, this section applies to rows rather than columns.

If a COLUMNS statement appears in PROC COMPUTAB, a target column must be selected for the incoming observation. If there is no COLUMNS statement, a new column is added for each observation. When a COLUMNS statement is present and the selection criteria fail to designate a column, the current observation is ignored. Faulty column selection can result in columns or entire tables of 0s (or missing values if the INITMISS option is specified).

During execution of the input block, when an observation is read, its values are copied into row variables in the program data vector (PDV).

To select columns, use either the column variable names themselves or the special variable _COL_. Use the column names by setting a column variable equal to some nonzero value. The example in the section Getting Started: COMPUTAB Procedure uses the logical expression COMPDIV= value, and the result is assigned to the corresponding column variable.

   a = compdiv = 'A';
   b = compdiv = 'B';
   c = compdiv = 'C';

IF statements can also be used to select columns. The following statements are equivalent to the preceding example:

   if      compdiv = 'A' then a = 1;
   else if compdiv = 'B' then b = 1;
   else if compdiv = 'C' then c = 1;

At the end of the input block for each observation, PROC COMPUTAB multiplies numeric input values by any nonzero selector values and adds the result to selected columns. Character values simply overwrite the contents already in the table. If more than one column is selected, the values are added to each of the selected columns.

Use the _COL_ variable to select a column by assigning the column number to it. The COMPUTAB procedure automatically initializes column variables and sets the _COL_ variable to 0 at the start of each execution of the input block. At the end of the input block for each observation, PROC COMPUTAB examines the value of _COL_. If the value is nonzero and within range, the row variable values are added to the CDT cells of the _COL_th column, for example,

   data rept;
      input div sales cgs;
   2   106    85
   3   120   114
   1    83    52
   proc computab data=rept;
      row div sales cgs;
      columns div1 div2 div3;
      _col_ = div;

The code in this example places the first observation (DIV=2) in column 2 (DIV2), the second observation (DIV=3) in column 3 (DIV3), and the third observation (DIV=1) in column 1 (DIV1).

Previous Page | Next Page | Top of Page