Category: Chapter 1 – Programs

Program 1.1


/****************************************************************************
* This program is taken from the following book. If using please cite it as:                            *
* Emrouznejad, A. and W. Ho (2012). Applied Operations Research with SAS, *
* CRC Press: Taylor Francis Ltd, ISBN: 9781439841303.*
* For details please visit: http://www.sas-or.com.                          *
****************************************************************************/

* Program 1.1: An example of PROC OPTMODEL, populating data (preparing SAS datasets prior to call OPTMODEL);
* Creating dataset of cost of shipments from each warehouse to publisher;

data d_trans;
input warehouse pub1-pub8 supply;
datalines;
1 10 15 12 13 15 10 20 15 1000
2 8 12 15 10 12 16 12 17 1500
3 12 12 16 14 12 15 10 12 2000
4 20 10 20 12 15 14 17 12 2000
;

* Creating dataset of demands by each publisher;
data d_demand;
input pub demand;
datalines;
1 200
2 500
3 700
4 800
5 900
6 900
7 1000
8 1500
;

/****************************************************************************
******************************END of the program*****************************
****************************************************************************/

Permanent link to this article: http://sas-or.com/book/program-1-1

Program 1.2


/****************************************************************************
* This program is taken from the following book. If using please cite it as:                            *
* Emrouznejad, A. and W. Ho (2012). Applied Operations Research with SAS, *
* CRC Press: Taylor Francis Ltd, ISBN: 9781439841303.*
* For details please visit: http://www.sas-or.com.                          *
****************************************************************************/

* Program 1.2: An example of PROC OPTMODEL, populating data,
* constructing linear programming and solving the model;

data d_trans;
input warehouse pub1-pub8 supply;
datalines;
1 10 15 12 13 15 10 20 15 1000
2 8 12 15 10 12 16 12 17 1500
3 12 12 16 14 12 15 10 12 2000
4 20 10 20 12 15 14 17 12 2000
;

data d_demand;
input pub demand;
datalines;
1 200
2 500
3 700
4 800
5 900
6 900
7 1000
8 1500
;

proc optmodel;

set WAREHOUSES;
set PUBS;

number demand{PUBS};
number cost{WAREHOUSES, PUBS};
number supply{WAREHOUSES};

var X{WAREHOUSES, PUBS} >= 0;

read data d_demand
into PUBS=[pub] demand[pub]=col(“demand”);

read data d_trans
into WAREHOUSES=[warehouse] supply[warehouse]=col(“supply”);

read data d_trans
into WAREHOUSES=[warehouse]
{p in PUBS} ;

min obj = sum{W in WAREHOUSES, P in PUBS} cost[w,p]*x[w,p];
con req_supply{w in WAREHOUSES}:

sum{p in PUBS} x[w,p] <= supply[w]; con req_demand{p in PUBS}: sum{w in WAREHOUSES} x[w,p] >= demand[p];

solve with lp/solver=primal;

create data optimout
from [warehouse pub]
={w in WAREHOUSES, p in PUBS: x[w,p]^=0}
amount=x;
quit;


/****************************************************************************
******************************END of the program*****************************
****************************************************************************/

Permanent link to this article: http://sas-or.com/book/program-1-2

Program 1.3


/****************************************************************************
* This program is taken from the following book. If using please cite it as:                            *
* Emrouznejad, A. and W. Ho (2012). Applied Operations Research with SAS, *
* CRC Press: Taylor Francis Ltd, ISBN: 9781439841303.*
* For details please visit: http://www.sas-or.com.                          *
****************************************************************************/

*Program 1.3: An example of PROC OPTMODEL;
proc optmodel;

* Declare parametrs a, b and c;
number c{1..4}=[4, 2, 1, 3] ;
number b{1..3}=[4, 3, 8];
number a{1..3, 1..4}= [2, 1, 0, 4,
4, -1, 4, 0,
3, 2, 1, 2];


* Declare variable x;
var x{1..4} >=0;

* Define objective function;
max z = sum{i in 1..4}(c[i]*x[i]);

* Define constraints;
con constraint{i in 1..3}:


sum{j in 1..4} a[i,j]*x[j] <= b[i];

* Print the linear programming;
expand;

* Solve the model;
solve;


* Print optimum solution for x;
print x.sol;
%put &_OROPTMODEL_;
quit;


/****************************************************************************
******************************END of the program*****************************
****************************************************************************/

Permanent link to this article: http://sas-or.com/book/program-1-3

Program 1.4


/****************************************************************************
* This program is taken from the following book. If using please cite it as:                            *
* Emrouznejad, A. and W. Ho (2012). Applied Operations Research with SAS, *
* CRC Press: Taylor Francis Ltd, ISBN: 9781439841303.*
* For details please visit: http://www.sas-or.com.                          *
****************************************************************************/

*Program 1.4: Set and indexing in PROC OPTMODEL;
proc optmodel;

set row ;
set col ;
row={“Bank1”, “Bank2”, “Bank3”, “Bank4”};
col={“Labour”, “Capital”, “Profit”};

number bank{r in row, c in col}=
[10, 2000, 30,
50, 40000, 68,
8, 25000, 45,
18, 70000, 50;

print bank;
quit;


/****************************************************************************
******************************END of the program*****************************
****************************************************************************/>

Permanent link to this article: http://sas-or.com/book/program-1-4

Program 1.5


/****************************************************************************
* This program is taken from the following book. If using please cite it as:                            *
* Emrouznejad, A. and W. Ho (2012). Applied Operations Research with SAS, *
* CRC Press: Taylor Francis Ltd, ISBN: 9781439841303.*
* For details please visit: http://www.sas-or.com.                          *
****************************************************************************/

*Program 1.5: An example of PROC OPTMODEL using read statement;
data bankdata;

input Bank $ Labour Capital Profit;
datalines;
Bank1 10 2000 30
Bank2 50 40000 68
Bank3 8 25000 45
Bank4 18 70000 50
;

proc optmodel;


* Define parameters;

set <string> row ;
set <string> col ;
col={“Labour”, “Capital”, “Profit”};

number bankmatrix{r in row, c in col};
* Populating name of banks from the first column of the dataset to ‘row’;

read data bankdata
into row=[Bank] ;
* Populating value of Capital, Labour and Profit to each bank from the dataset;

read data bankdata
into
{r in row} <bankmatrix[r, “Labour”]=col(“Labour”)
bankmatrix[r, “Capital”]=col(“Capital”)
bankmatrix[r, “Profit”]=col(“Profit”)>;

* Printing bankmatrix;
print bankmatrix;

quit;

/****************************************************************************
******************************END of the program*****************************
****************************************************************************/

Permanent link to this article: http://sas-or.com/book/program-1-5