I need to transform the output from PROC OPTMODEL in a SAS table.
Browsing on the internet, I found it is possible to do that by using the CREATE DATA statement in the PROC OPTMODEL.
Specifically, I'm tryng to solve an optimization problem that aims to minimize the volatility under 2 constraints; the example script is the following one:
proc optmodel;;
/* let x1, x2, x3, x4 be the amount invested in each asset */
var x{1..&n.} >= 0;
num coeff{1..&n., 1..&n.} = [&covariance_matrix.];
num r{1..&n.} = [&return.];
/* minimize the variance of the portfolio's total return */
minimize f = sum{i in 1..&n., j in 1..&n.}coeff[i,j]*x[i]*x[j];
/* subject to the following constraints */
con BUDGET: sum{i in 1..&n.}x[i] <= &budget.;
con GROWTH: sum{i in 1..&n.}r[i]*x[i] >= &growth. * &budget.;
solve with NLP;
create data weights from x;
/* print the optimal solution */
print x;
quit;
I aim to transform the vector x in a SAS table, in order to be able to use the weights that minimize the volatility; the log window shows the following error message:
ERROR 650-782: The subscript count does not match array 'x', 2 NE 1.
Why do I get such error?Can someone can help me to get a solution?
In case the question is not clear, fell free to text me in the comment here below.
Thanks all in advance!!
I solved by running the following statement:
create data weights from [n]x