The OPTMODEL Procedure |
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.
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.
The array index columns show the set of valid index values for the print items in the table. The array index column for the th 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.
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.
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.
Copyright © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.