| The OPTMODEL Procedure |
create data resdata from [solns]=indset opt;
proc optmodel;
number m = 7, n = 5;
create data example from m n;
proc optmodel;
number m = 7, n = 5;
create data example from ratio=(m/n);
proc optmodel;
number m = 7, n = 5;
create data example from col("s"||n)=(m+n);
proc optmodel;
set<string> alph = {'a', 'b', 'c'};
var x{1..3, alph} init 2;
create data example from [i]=(1..3)
{j in alph}<col("x"||j)=x[i,j]>;
proc optmodel;
number m = 7, n = 5;
create data example from m n ratio=(m/n) col("s"||n)=(m+n);
proc print;
run;
A key-set in the CREATE DATA statement explicitly specifies the set of index values. Key-set can be specified as a set expression, although it must be enclosed in parentheses if it contains any function calls or operators. Key-set can also be specified as an index set expression, in which case the index-set dummy parameters override any dummy parameters that are declared in the key-column(s) items. The following code creates a data set from the PROC OPTMODEL parameter m, a matrix whose only nonzero entries are located at (1, 1) and (4, 1):
proc optmodel;
number m{1..5, 1..3} = [[1 1] 1 [4 1] 1];
create data example
from [i j] = {setof{i in 1..2}<i**2>, {1, 2}} m;
proc print data=example noobs;
run;
The dummy parameter i in the SETOF expression takes precedence over
the dummy parameter i declared in the key-column(s) item. The
output from this code is shown in Output 6.11.
If no key-set is specified, then the set of index values is formed from the union of the index sets of the implicitly indexed column(s) . The number of index elements for each implicitly indexed array must match the number of key-column(s) . The type of each index element (string versus numeric) must match the element of the same position in other implicit indices.
The arrays for implicitly indexed columns in a CREATE DATA statement do not need to have identical index sets. A missing value is supplied for the value of an implicitly indexed array location when the implied index value is not in the array's index set.
In the following code, the key-set is unspecified. The set of index
values is
, which is the union of the index sets of
x and y. These index sets are not identical, so missing values
are supplied when necessary. The results of this code are shown in
Output 6.12.
proc optmodel;
number x{1..2} init 2;
var y{2..3} init 3;
create data exdata from [keycol] x y;
proc print;
run;
The types of the output data set variables match the types of the source values. The output variable type for a key-column(s) matches the corresponding element type in the index value tuple. A numeric element matches a NUMERIC data set variable, while a string element matches a CHAR variable. For regular column(s) the source expression type determines the output data set variable type. A numeric expression produces a NUMERIC variable, while a string expression produces a CHAR variable.
Lengths of character variables in the output data set are determined automatically. The length is set to accommodate the longest string value output in that column.
You can use the iterated column(s) form to output selected rows of multiple arrays, assigning a different data set variable to each column. For example, the following code outputs the last two rows of the two-dimensional array, a, along with corresponding elements of the one-dimensional array, b:
proc optmodel;
num m = 3; /* number of rows/observations */
num n = 4; /* number of columns in a */
num a{i in 1..m, j in 1..n} = i*j; /* compute a */
num b{i in 1..m} = i**2; /* compute b */
set<num> subset = 2..m; /* used to omit first row */
create data out
from [i]=subset {j in 1..n}<col("a"||j)=a[i,j]> b;
To specify the data set to be created, the CREATE DATA statement uses the form key-column(s) {index set}<column(s)> column(s). The preceding code creates a data set out, which has
observations and
variables. The variables are named i, a1
through a
, and b, as shown in Output 6.13.
See the section "Data Set Input/Output" for more examples of using the CREATE DATA statement.
Copyright © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.