## PROC OPTMODEL

Solved
Occasional Contributor
Posts: 8

# PROC OPTMODEL

I often PROC OPTMODEL, especially for cases where I need the solver to run group by group on a single dataset and am extremely impressed with the functionality. Recently I was trying to run it for a problem where there is more than one set of decision variables. Even after going through several examples on many of the problems posted on these fora I was unable to find one that involves multiple set of of decision variables. A typical PROC OPTMODEL objective function looks like

min z = <formula that requires adjusting the decision variable so that z can be minimized>

However, in the present case I'm working on the decision variables are functions of other values. For e.g. in my dataset I have variables a, b and c and a dependent value f as follows

abcf (depending on a, b and c)

1

540.2
1650.3
2530.21
2640.31
3520.42
3630.81
4510.92
4620.11

For values of a, b and c we have functions A(a), B(b) and C(c). The objective function needs to minimize the difference between sum of square of difference of f(a,b,c) and A(a)*B(b)*C(c) and initializing A(a), B(b) and C(c) as 1. The decision variables in this case are A(a),B(b) and C(c). Any help on putting the objective function in PROC OPTMODEL syntax  will be greatly appreciated.

Accepted Solutions
Solution
‎11-07-2014 10:49 AM
SAS Employee
Posts: 538

## Re: PROC OPTMODEL

data indata;
input a b c f;
datalines;
1  5  4  0.2
1  6  5  0.3
2  5  3  0.21
2  6  4  0.31
3  5  2  0.42
3  6  3  0.81
4  5  1  0.92
4  6  2  0.11
;

proc optmodel;
set OBS;
set PARAMS = {'a','b','c'};
num data {OBS, PARAMS};
num f {OBS};
read data indata into OBS=[_N_] {j in PARAMS} <data[_N_,j]=col(j)> f;
print data f;

set VALUES {j in PARAMS} = setof {i in OBS} data[i,j];

var X {j in PARAMS, v in VALUES} >= 0 <= 10 init 1;
impvar Error {i in OBS} = prod {j in PARAMS} X[j,data[i,j]] - f;
min SSE = sum {i in OBS} Error^2;

solve with NLP / ms;

num prod {i in OBS} = prod {j in PARAMS} X[j,data[i,j]].sol;
print X;
print prod f Error;
quit;

All Replies
SAS Employee
Posts: 538

## Re: PROC OPTMODEL

You might find these two examples helpful:

42332 - BY group processing with PROC OPTMODEL

SAS/OR(R) 13.2 User's Guide: Mathematical Programming Examples

If not, please post what you have tried so far.

Occasional Contributor
Posts: 8

## Re: PROC OPTMODEL

Hi Rob,

Thanks for sharing the example, however it does not capture my problem.

I have created an illustrative problem in a spreadsheet attached with this reply. You will see that A(a), B(b) and C(c) vector lengths are not of the same length as the data set because length of A(a) is equal to the number of unique values for a and so on for B(b) and C(c). The cell being minimized is M11.

I am not able to share any work in progress SAS code because I have not been able to figure out how to start with coding this.

Thanks,

Parikshit

Solution
‎11-07-2014 10:49 AM
SAS Employee
Posts: 538

## Re: PROC OPTMODEL

data indata;
input a b c f;
datalines;
1  5  4  0.2
1  6  5  0.3
2  5  3  0.21
2  6  4  0.31
3  5  2  0.42
3  6  3  0.81
4  5  1  0.92
4  6  2  0.11
;

proc optmodel;
set OBS;
set PARAMS = {'a','b','c'};
num data {OBS, PARAMS};
num f {OBS};
read data indata into OBS=[_N_] {j in PARAMS} <data[_N_,j]=col(j)> f;
print data f;

set VALUES {j in PARAMS} = setof {i in OBS} data[i,j];

var X {j in PARAMS, v in VALUES} >= 0 <= 10 init 1;
impvar Error {i in OBS} = prod {j in PARAMS} X[j,data[i,j]] - f;
min SSE = sum {i in OBS} Error^2;

solve with NLP / ms;

num prod {i in OBS} = prod {j in PARAMS} X[j,data[i,j]].sol;
print X;
print prod f Error;
quit;

Occasional Contributor
Posts: 8

## Re: PROC OPTMODEL

Thank you Rob. I'll try it out and let you know how it worked.

Occasional Contributor
Posts: 8

## Re: PROC OPTMODEL

Thanks a lot Rob. We were able to implement the code on real data and it worked just like we expected it to. We also added a line to extract X into a dataset looking at one of the examples from the SAS support pages on OPTMODEL. It is

create data param_values from [param_name param_value]= {j in PARAMS, v in VALUES} value=X;

Thanks again for your valuable help.

🔒 This topic is solved and locked.