SAS Optimization, and SAS Simulation Studio

turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-06-2014 08:41 AM

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

a | b | c | f (depending on a, b and c) |
---|---|---|---|

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 |

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-07-2014 10:49 AM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-06-2014 06:02 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-07-2014 02:45 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-07-2014 10:49 AM

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

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-08-2014 11:23 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-11-2014 07:29 AM

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

Thanks again for your valuable help.