Turn on suggestions

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

Showing results for

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 01-22-2019 11:28 AM
(892 views)

For a simplified case, let's assume, I have following data:

id | cost | profit_in_case1 | profit_in_case2 |

A | -1 | 10 | 11 |

B | -0.6 | 10 | 5 |

C | -0.75 | 10 | 10.5 |

D | -0.75 | 10.5 | 10 |

And I have to maximize my profit with decisions,so if I just see the profits as individual rows, I'll have decisions like -

A - case2, B - case1, C - case2, D-case1.

But I have constraints like, I can only avail costs up to 1.5, so I can't choose A-case2 and B-case1 or A-case2 and C-case2(D-case1), instead I have to choose : C-case2 and D-case1. The final decision for maximum profit will look like:

decision_Cost | decision_profit_case1 | decision_profit_case2 |

1 | 0 | 0 |

1 | 0 | 0 |

0 | 0 | 1 |

0 | 1 | 0 |

This way, we have minimized cost (Total = 1.33) and maximized profit (Total = 21) in the constraints that we can chose only one of the decisions to be 1 and total cost doesn't breach the boundary of 1.5.

My original problem has other constraints as well, but if I can get a solution to this one in PROC IML or PROC OPTMODEL, I think I can build from there. Any help is deeply appreciated. I am using SAS 9.4

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I think the following does what you want, using PROC OPTMODEL in SAS/OR:

```
data have;
input id $ cost profit_in_case1 profit_in_case2;
cost = -cost;
datalines;
A -1 10 11
B -0.6 10 5
C -0.75 10 10.5
D -0.75 10.5 10
;
proc optmodel;
set <str> ITEMS;
num cost {ITEMS};
set CASES = 1..2;
num profit {ITEMS, CASES};
read data have into ITEMS=[id] cost {j in CASES} <profit[id,j]=col('profit_in_case'||j)>;
var X {ITEMS, CASES} binary;
max TotalProfit = sum {i in ITEMS, j in CASES} profit[i,j] * X[i,j];
con ChooseOne {i in ITEMS}:
sum {j in CASES} X[i,j] <= 1;
con Budget:
sum {i in ITEMS, j in CASES} cost[i] * X[i,j] <= 1.5;
solve;
print X;
quit;
```

6 REPLIES 6

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I think the following does what you want, using PROC OPTMODEL in SAS/OR:

```
data have;
input id $ cost profit_in_case1 profit_in_case2;
cost = -cost;
datalines;
A -1 10 11
B -0.6 10 5
C -0.75 10 10.5
D -0.75 10.5 10
;
proc optmodel;
set <str> ITEMS;
num cost {ITEMS};
set CASES = 1..2;
num profit {ITEMS, CASES};
read data have into ITEMS=[id] cost {j in CASES} <profit[id,j]=col('profit_in_case'||j)>;
var X {ITEMS, CASES} binary;
max TotalProfit = sum {i in ITEMS, j in CASES} profit[i,j] * X[i,j];
con ChooseOne {i in ITEMS}:
sum {j in CASES} X[i,j] <= 1;
con Budget:
sum {i in ITEMS, j in CASES} cost[i] * X[i,j] <= 1.5;
solve;
print X;
quit;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi @RobPratt, thanks very much, this works perfectly. Many thanks.

Is there a source where I can read more about the features PROC OPTMODEL have with examples?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Try this CREATE DATA statement:

```
create data want from [id]=ITEMS {j in CASES} <col('X'||j)=X[id,j]>;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The official documentation is a good source:

http://support.sas.com/documentation/onlinedoc/or/

See especially these two:

- SAS/OR 15.1 User's Guide: Mathematical Programming
- SAS/OR 15.1 User's Guide: Mathematical Programming Examples

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thank you very much. Works like a charm.😊

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer.

** **

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.