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 04-27-2019 01:18 AM
(652 views)

proc optmodel;

set supply= {"S1","S2"};

set distr= {"SGD","MYD","IDD","VND","THD"};

set plant= {"SG","MY","ID","VN","TH"};

number Suppliercap {supply}=[2000,2000];

number AnnualDemand {plant}=[

150 300 150 150 300];

number timeperiods = 6;

number matcost = 40;

number packcost = 5;

number Leg1Trcost {supply,distr}=[

12 12 14 16 18

14 12 14 18 16] ;

number Leg2Trcost {distr,plant}=[

0 4 4 6 5

3 0 4 4 5

3 4 0 4 6

5 4 6 0 3

5 6 4 3 0];

number Pmin = 1;

number Pmax = 5;

var Firstlegsupply {supply,distr} >= 0;

var Secondlegsupply {distr,plant} >= 0;

var open {distr} binary;

minimize Total_Cost= sum {i in supply,k in distr} Firstlegsupply[i,k]*(Leg1Trcost[i,k]+matcost) +

sum {k in distr,j in plant} Secondlegsupply[k,j]*(Leg2Trcost[k,j]+matcost+packcost);

con MaxS {i in supply} :

sum {k in distr} Firstlegsupply[i,k] <= Suppliercap[i];

con MinD {j in plant} :

sum {k in distr} Secondlegsupply[k,j]*timeperiods = AnnualDemand[j];

con NoStock {k in distr} :

sum {i in supply} Firstlegsupply[i,k] = sum {j in plant} Secondlegsupply[k,j];

con linkingcons{k in distr,j in plant}:

Secondlegsupply[k,j]-2000*open[k]<=0;

con mindistr :

sum{k in distr}open[k]>= Pmin;

con maxdistr :

sum{k in distr}open[k]<= Pmax;

con minqty{k in distr,j in plant}:

Secondlegsupply[k,j]<=25;

con maxqty{k in distr,j in plant}:

Secondlegsupply[k,j]<=100;

solve;

print Total_Cost;

print {k in distr} (sum {i in supply} Firstlegsupply[i,k]);

print Secondlegsupply;

quit;

The above is my code which will output Total cost, and flows during 2 legs of material supply.

In addition to this i want to seperately print Transportation cost during both legs for the optimized quantities.i.e.

1. sum {i in supply,k in distr} Firstlegsupply[i,k]*Leg1Trcost[i,k];

2. sum {k in distr,j in plant} Secondlegsupply[k,j]*Leg2Trcost[k,j];

Could you kindly advise on how to write code for this.

Do i need to define additional variables and assign this equation. As you can see this is portion of objective function. And i want the function to calculate the value based on optimised values for FirstLegsupply and Secondlegsupply.

3 REPLIES 3

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

Just use PRINT with parentheses:

print (your expression);

print (your expression);

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

Hello Rob,

Thank you very much for your response. I am very sorry for my ignorance as I am new to this software.

I had tried the same but without using parentheses.

With your suggestion, I am able to print the value and they appear just as a number.

In order that the results displayed are self-explanatory, may I know how to associate it with a name. Example for the objective function, the result is displayed as **Total_cost** and then the numeric value.

Your response is highly appreciated and will be of great help.

Regards,

Errol Tauro

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

Here are four ways:

```
print "my string";
print (expression);
print "my string" (expression);
impvar myimpvar = expression;
print myimpvar;
num mynum = expression with .sol suffix for each variable;
print mynum;
```

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.