The OPTMODEL Procedure

PRINT Statement

PRINT print-item(s);

The PRINT statement outputs string and numeric data in tabular form. The statement specifies a list of arrays or other data items to print. Multiple items can be output together as data columns in the same table.

If no format is specified, the PRINT statement handles the details of formatting automatically (see the section "Formatted Output" for details). The default format for a numerical column is the fixed-point format (w.d format), which is chosen based on the values of the PDIGITS= and PWIDTH= options (see the section "PROC OPTMODEL Statement") as well as the values in the column. The PRINT statement uses scientific notation (the Ew. format) when a value is too large or too small to display in fixed format. The default format for a character column is the $w. format, where the width is set to be the length of the longest string (ignoring trailing blanks) in the column.

Print-item can be specified in the following forms:

identifier-expression [format]
specifies a data item to output. Identifier-expression can name an array. In that case all defined array locations are output. Format specifies a SAS format that overrides the default format.

(expression) [format]
specifies a data value to output. Format specifies a SAS format that overrides the default format.

{index-set} identifier-expression [format]
specifies a data item to output under the control of an index set. The item is printed as if it were an array with the specified set of indices. This form can be used to print a subset of the locations in an array, such as a single column. If the identifier-expression names an array, then the indices of the array must match the indices of the index-set. Format specifies a SAS format that overrides the default format.

{index-set} (expression) [format]
specifies a data item to output under the control of an index set. The item is printed as if it were an array with the specified set of indices. In this form the expression is evaluated for each member of the index-set to create the array values for output. Format specifies a SAS format that overrides the default format.

string
specifies a string value to print.



_PAGE_
specifies a page break.

The following example demonstrates the use of several print-item forms:

    proc optmodel;
       num x = 4.3;
       var y{j in 1..4} init j*3.68;
       print y; /* identifier-expression */
       print (x * .265) dollar6.2; /* (expression) [format] */
       print {i in 2..4} y; /* {index-set} identifier-expression */
       print {i in 1..3}(i + i*.2345692) best7.; 
                                   /* {index-set} (expression) [format] */
       print "Line 1"; /* string */
 

The output is displayed in Output 6.19.

The OPTMODEL Procedure

[1] y
1 3.68
2 7.36
3 11.04
4 14.72

$1.14

[1] y
2 7.36
3 11.04
4 14.72

[1]  
1 1.23457
2 2.46914
3 3.70371

Line 1


Figure 6.19: Print-item Forms

Adjacent print items that have similar indexing are grouped together and output in the same table. Items have similar indexing if they specify arrays that have the same number of indices and have matching index types (numeric versus string). Nonarray items are considered to have the same indexing as other nonarray items. The resulting table has a column for each array index followed by a column for each print item value. This format is called list form. For example, the following code produces a list form table:

    proc optmodel;
       num a{i in 1..3} = i*i;
       num b{i in 3..5} = 4*i;
       print a b;
 

This code produces the listing output in Output 6.20.

[1] a b
1 1  
2 4  
3 9 12
4   16
5   20


Figure 6.20: List Form PRINT Table

The array index columns show the set of valid index values for the print items in the table. The array index column for the ith index is labeled [i]. There is a row for each combination of index values that was used. The index values are displayed in sorted ascending order.

The data columns show the array values that correspond to the index values in each row. If a particular array index is invalid or the array location is undefined, then the corresponding table entry is displayed as blank for numeric arrays and as an empty string for string arrays. If the print items are scalar, then the table has a single row and no array index columns.

If a table contains a single array print item, the array is two-dimensional (has two indices), and the array is dense enough, then the array is shown in matrix form . In this format there is a single index column that contains the row index values. The label of this column is blank. This column is followed by a column for every unique column index value for the array. The latter columns are labeled by the column value. These columns contain the array values for that particular array column. Table entries that correspond to array locations that have invalid or undefined combinations of row and column indices are blank or (for strings) printed as an empty string.

The following code generates a simple example of matrix output:

    proc optmodel;
       print {i in 1..6, j in i..6} (i*10+j);
 

The PRINT statement produces the output in Output 6.21.

  1 2 3 4 5 6
1 11 12 13 14 15 16
2   22 23 24 25 26
3     33 34 35 36
4       44 45 46
5         55 56
6           66


Figure 6.21: Matrix Form PRINT Table

The PRINT statement prints single two-dimensional arrays in the form that uses fewer table cells (headings are ignored). Sparse arrays are normally printed in list form, and dense arrays are normally printed in matrix form. In a PROC OPTMODEL statement, the PMATRIX= option enables you to tune how the PRINT statement displays a two-dimensional array. The value of this option scales the total number of nonempty array elements, which is used to compute the tables cells needed for list form display. Specifying values for the PMATRIX= option less than 1 causes the list form to be used in more cases, while specifying values greater than 1 causes the matrix form to be used in more cases. If the value is 0, then list form is always used. The default value of the PMATRIX= option is 1. Changing the default can be done with the RESET OPTIONS statement.

The following code illustrates how the PMATRIX= option affects the display of the PRINT statement:

    proc optmodel;
       num a{i in 1..6, i..i} = i;
       num b{i in 1..3, j in 1..3} = i*j;
       print a;
       print b;
       reset options pmatrix=3;
       print a;
       reset options pmatrix=0.5;
       print b;
 

The output is shown in Output 6.22.

The OPTMODEL Procedure

[1] [2] a
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6

b
  1 2 3
1 1 2 3
2 2 4 6
3 3 6 9

a
  1 2 3 4 5 6
1 1          
2   2        
3     3      
4       4    
5         5  
6           6

[1] [2] b
1 1 1
1 2 2
1 3 3
2 1 2
2 2 4
2 3 6
3 1 3
3 2 6
3 3 9


Figure 6.22: PRINT Statement: Effects of PMATRIX= Option

From Output 6.22, it can be seen that by default, the PRINT statement tries to make the display compact. However, the default can be changed by using the PMATRIX= option.

Previous Page | Next Page | Top of Page