BookmarkSubscribeRSS Feed
Calcite | Level 5

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];


print x;


Any help is greatly appreciated!


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.

Calcite | Level 5

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. 

Register now!

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.

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