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

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

Posted 10-25-2021 12:25 PM
(238 views)

I'm new to SAS and not very familiar with summation notation so learning both. I have the following problem: two products: "Gin" and "Kol" produced in three locations: "Eth" "Tan" "Nig" with variable cost as follows:

Gin Kol

Eth 21.00 22.50

Tan 22.50 24.50

Nig 23.00 25.50

Constraints are

demand for Gin is 550 and for Kol is 450

plant capacity Eth 425 Tan 400 Nig 750

My error ridden code so far is:

```
proc optmodel;
set loc={"Eth", "Tan", "Nig"};
set type={"Gin", "Kol"};
number cost{type, loc}=[21.00 22.50
22.50 24.50
23.00 25.50];
number dem{type}=[550 450];
number cap{loc}=[425 400 750];
number fc{loc}=[1500 2000 3000];
var x{loc, type} >=0;
var y binary;
minimize total_cost = sum{i,j in x, i,j in cost} x[i,j]*cost[i,j];
con capacity: sum{i in loc}x[i,j]<=cap[i];
con demand: sum{j in type}x[i,j]<=dem[j];
solve;
print x;
quit;
```

Any help is greatly appreciated!

2 REPLIES 2

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

In the cost declaration, the syntax is correct, but you need to reverse the arguments:

```
/*number cost{type, loc}=[21.00 22.50 */
number cost{loc, type}=[21.00 22.50
```

In the objective declaration, you need to refer to the index sets in the SUM operator:

```
/*minimize total_cost = sum{i,j in x, i,j in cost} x[i,j]*cost[i,j];*/
minimize total_cost = sum{i in loc, j in type} x[i,j]*cost[i,j];
```

In the capacity constraint declaration, you need an index for each constraint, and the sum is over j:

```
/*con capacity: sum{i in loc}x[i,j]<=cap[i];*/
con capacity{i in loc}: sum{j in type}x[i,j]<=cap[i];
```

In the demand constraint declaration, you need an index for each constraint, the sum is over i, and the <= should be >=:

```
/*con demand: sum{j in type}x[i,j]<=dem[j];*/
con demand{j in type}: sum{i in loc}x[i,j]>=dem[j];
```

As a new user, you might find this book of examples helpful.

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

This helps tremendously. Thanks so much.

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

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.