TEMPLATE Procedure: Creating Table Templates

Using the TEMPLATE Procedure to Create Tabular Output

Values in Table Columns and How They Are Justified

The process of justifying the values in columns in a LISTING output is determined by the format of the variable and the values of two attributes: JUST= and JUSTIFY=. It is a three-step process:
  1. ODS puts the value into the format for the column. Character variables are left-justified within their format fields; numeric variables are right-justified.
  2. ODS justifies the entire format field within the column width according to the value of the JUST= attribute for the column, or, if that attribute is not set, JUST= for the table. For example, if you right-justify the column, the format field is placed as far to the right as possible. However, the placement of the individual numbers and characters within the field does not change. Thus, decimal points remain aligned. If the column and the format field have the same width, then JUST= has no apparent effect because the format field occupies the entire column.
  3. If you specify JUSTIFY=ON for the column or the table, ODS justifies the values within the column without regard to the format field. By default, JUSTIFY=OFF.
For example, consider this set of values:
123.45
234.5
.
987.654
If the values are formatted with a 6.2 format and displayed in a column with a width of 6, they appear this way, regardless of the value of JUST= (asterisks indicate the width of the column):
******
123.45
234.50
   .
987.65
If the width of the column increases to 8, then the value of JUST= does affect the placement of the values, because the format field has room to move within the column. Notice that the decimal points remain aligned but that the numbers shift in relation to the column width.
just=left                 just=center                 just=right

********                  ********                    ********
123.45                     123.45                       123.45
234.50                     234.50                       234.50
   .                          .                            .
987.65                     987.65                       987.65
Now, if you add JUSTIFY=ON, then the values are formatted within the column without regard to the format width. The results are as follows:
justify=on                justify=on                  justify=on
just=left                 just=center                 just=right

********                  ********                    ********
123.45                     123.45                       123.45
234.50                     234.50                       234.50
.                            .                               .
987.65                     987.65                       987.65
All destinations except LISTING justify the values in columns as if JUSTIFY=ON.

Formatting Values in Table Columns

The process of formatting the values in columns in a LISTING output is determined by the format of the variable and the values of three options: FORMAT=, FORMAT_WIDTH=, and FORMAT_NDEC=. It is a four-step process:
  1. If you omit a FORMAT= option, then the format that the data component provides is used. If the data component does not provide a format, then ODS uses one of the following:
    • best8. for integers
    • D12.3 for doubles
    • the length of the variable for character variables
  2. If a format width is specified in the FORMAT= option, then it will take precedence over the FORMAT_WIDTH= and FORMAT_NDEC= options.
  3. If you specify a decimal width with the FORMAT= and FORMAT_NDEC= options, then the format that is specified with the FORMAT= option is used.
  4. If you specify a format width with the FORMAT= and FORMAT_WIDTH= options, then the format that is specified with FORMAT= option is used.
The formatting attributes of a column are determined by the data component or the column template. This table summarizes the behavior of the column formatting attributes based on which attributes the column template provides.
Summary of Column Formatting Attributes
Specifications Provided by the Column Template
Result
Nothing
Format name, width, and number of decimal places are determined by the data component.
Format name
Format name and width are determined by the column template; number of decimal places is determined by the data component.
Format name and width
Format name and width are determined by the column template.
Format name, width, and number of decimal places
All three are determined by the column template.
Width
No name is specified; width is determined by the column template; number of decimal places is determined by the data component.
Number of decimal places
No name is specified; width is determined by the data component; number of decimal places is determined by the column template.

Stacking Values for Two or More Variables

To stack values for two or more variables in the same column, put parentheses around the stacked variables. In such a case, the column header for the first column inside the parentheses becomes the header for the column that contains all the variables inside parentheses. For example, this COLUMN statement produces a template with the following characteristics:
  • The value of NAME is in the first column by itself.
  • The values of CITY and STATE appear in the second column with CITY above STATE. The header for this column is the header that is associated with CITY.
  • The values HOMEPHONE and WORKPHONE appear in the third column with HOMEPHONE above WORKPHONE. The header for this column is the header that is associated with HOMEPHONE.
    column name (city state) (homephone workphone);
Use the asterisk (*) in the COLUMN statement to change the layout of stacking variables. An asterisk between groups of variables in parentheses stacks the first item in the first set of parentheses above the first item in the next set of parentheses, and so on, until the last group of parentheses is reached. Then, the second item in the first group is stacked above the second item in the second group, and so on. For example, this COLUMN statement produces a report with the following characteristics:
  • The value of NAME is in the first column by itself.
  • The values of CITY and HOMEPHONE appear in the second column with CITY above HOMEPHONE. The header for this column is the header that is associated with CITY.
  • The values STATE and WORKPHONE appear in the third column with STATE above WORKPHONE. The header for this column is the header that is associated with STATE.
    column name (city state) * (homephone workphone);