## Need help with basic code, proc optmodel, summation notation

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

## Re: Need help with basic code, proc optmodel, summation notation

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.

## Re: Need help with basic code, proc optmodel, summation notation

This helps tremendously.  Thanks so much.

Discussion stats
• 2 replies
• 239 views
• 1 like
• 2 in conversation