Author's posts

To order this book


Still not ordered the book!

Click here to order.

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

Data Files

Chapter 2

Data2_1.txt
Data2_2.txt
Data2_3.txt

Chapter 3

Data3_1.txt
Data3_2.txt
Data3_3.txt

Chapter 4

Data4_1.txt
Data4_2.txt

Chapter 5

Data5_1.txt

Chapter 6

Data6_1.txt

Chapter 7

Data7_1_C.txt
Data7_1_T.txt
Data7_2.txt
Data7_3_F.txt
Data7_3_C.txt

Chapter 8

Data8_1_A.txt
Data8_1_C.txt
Data8_2.txt

Chapter 9

Data9_1.txt
Data9_2_In.txt
Data9_2_Out.txt
Data9_3_In_p1.txt
Data9_3_In_p2.txt
Data9_3_Out_p1.txt
Data9_3_Out_p2.txt

Appendices

mydata.csv
mydata.txt
mydata.xls
mydata.xlsx

_________________________________________________________________________

Chapter 2 [exercises]

Data2_1_exercise.txt
Data2_2_exercise.txt
Data2_3_exercise.txt

Chapter 3 [exercises]

Data3_1_exercise.txt
Data3_2_exercise.txt
Data3_3_exercise.txt

Chapter 4 [exercises]

Data4_1_exercise.txt
Data4_2_exercise.txt

Chapter 5 [exercises]

Data5_1_exercise.txt

Chapter 6 [exercises]

Data6_1_exercise.txt

Chapter 7 [exercises]

Data7_1_C_exercise.txt
Data7_1_T_exercise.txt
Data7_2_exercise.txt
Data7_3_F_exercise.txt
Data7_3_C_exercise.txt

Chapter 8 [exercises]

Data8_1_A_exercise.txt
Data8_1_C_exercise.txt
Data8_2_exercise.txt

Chapter 9 [exercises]

Data9_1_exercise.txt
Data9_2_In_exercise.txt
Data9_2_Out_exercise.txt
Data9_3_In_p1_exercise.txt
Data9_3_In_p2_exercise.txt
Data9_3_Out_p1_exercise.txt
Data9_3_Out_p2_exercise.txt

Permanent link to this article: http://sas-or.com/book/data-files

Register to access codes

To access to this website you need to buy the book and register here .

Permanent link to this article: http://sas-or.com/book/not-registered-yet

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

Program 2.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 2.1: Using PROC OPTMODEL for Transportation problem;
option nodate ;
%let _title=’Example 2.1: Transportation problem for four suppliers and five customers.’;
%let _data=’c:\sasor\data2_1.txt’;

* The data handling macro;
%macro data;
* Import text tab delimited data file to SAS data file;

proc import
datafile=&_data
out=dcost
dbms=tab
replace;
getnames=yes;
run;
%mend data;

%macro model;
* Starting OPTMODEL Procedure;
proc optmodel;

* Define sets;
set SUPPLIERS;
set CUSTOMERS={1..5};

* Define parameters;
number demand{CUSTOMERS};
number supply{SUPPLIERS};
number cost{SUPPLIERS, CUSTOMERS};

* Define variables;
var X{SUPPLIERS, CUSTOMERS} >= 0;

* Load the supplier set and their amount of supply;
read data dcost (where= (supply ne .))
into SUPPLIERS=[Supplier] supply[Supplier]=col(“supply”);

* Load the customer set and their demand;
read data dcost (where= (supply eq .)) into
{c in CUSTOMERS} ;

* Load the cost of shipment from each supplier to each customer;
read data dcost (where= (supply ne .))
into SUPPLIERS=[Supplier]
{c in CUSTOMERS} ;

* Define objective function;
min obj = sum{s in SUPPLIERS, c in CUSTOMERS} cost[s,c]*x[s,c];

* Define constraints;
con req_supply{s in SUPPLIERS}:
sum{c in CUSTOMERS} x[s,c] <= supply[s];

con req_demand{c in CUSTOMERS}: sum{s in SUPPLIERS} x[s,c] >= demand[c];

con zero{c in CUSTOMERS, s in SUPPLIERS : cost[s,c]=1E10}: x[s,c]=0;

* Solve the model;
solve with lp/solver=primal;

* Create optimum values in a SAS dataset ‘optimout’;
create data optimout
from [SUPPLIERS CUSTOMERS]
={s in SUPPLIERS, c in CUSTOMERS: x[s,c]^=0}
amount=x;

* End of OPTMODEL Procedure;
quit;
%mend model;

* The report writing macro;
%macro report;

* report the results in a tabulated form;
proc tabulate data=optimout;
title &_title;
class SUPPLIERS CUSTOMERS ;
var amount;
table SUPPLIERS =” Suppliers”,
CUSTOMERS*amount*sum
/ BOX=’Amount of suppliers to customers’ ;
run;
%mend report;

* The ortrans macro for transportation problem;
%macro ortrans;
%data;
%model;
%report;
%mend ortrans;

%ortrans;


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

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

Program 2.2


/****************************************************************************
* This program is taken from the following book:                            *
* Emrouznejad, A. and Ho, W. (2010) Applied Operational Research with SAS,  *
* Chapman and Hall/CRC – 284 Pages.                                         *
* For details please visit: http://www.sas-or.com.                          *
****************************************************************************/


* Using PROC OPTMODEL for Assignment problem;
option nodate ;
%let _title=’Assignment network for five workers and five tasks.’;
%let _data=’c:\sasor\data2_2.txt’;

* The data handling macro;
%macro data;
* Import text tab delimited data file to SAS data file;

proc import
datafile=&_data
out= dataassign
dbms=tab
replace;
getnames=yes;
run;
%mend data;

%macro model;

* Starting OPTMODEL Procedure;
proc optmodel;

* Define sets;
set WORKERS;
set TASKS={1..5};

* Define parameters;
number costprofit{WORKERS, TASKS};

* Define variables;
var X{WORKERS, TASKS} integer >= 0;

* Load the cost/profit matrix ;
read data dataassign
into WORKERS=[worker]
{t in TASKS} ;

* Define objective function;
min obj = sum{w in WORKERS, t in TASKS} costprofit[w,t]*x[w,t];

* Define constraints;
con req_supply{w in WORKERS}:
sum{t in TASKS} x[w,t] = 1;

con req_demand{t in TASKS}:
sum{w in WORKERS} x[w,t] = 1;

* Solve the model;
solve with milp;

* Create optimum values in a SAS dataset ‘optimout’;
create data optimout
from [WORKERS TASKS]
={w in WORKERS, t in TASKS: x[w,t]^=0}
amount=x cp= costprofit[w,t];

* End of OPTMODEL Procedure;
quit;

%mend model;

%macro report;
* Report the results in a tabulated form;
proc tabulate data=optimout;
title &_title;
class WORKERS TASKS ;
var amount;
table WORKERS =” Workers”,
TASKS*amount*sum
/ BOX=’Assigning workers to each tasks’ ;
run;

* Report the results in a tabulated form;
proc tabulate data=optimout;
title &_title;
class WORKERS TASKS ;
var cp;
table WORKERS =” Workers”,
TASKS*cp*sum
/ BOX=’Cost-profit of workers to each tasks’ ;
run;
%mend report;

* The orassign macro for assignment problem;

%macro orassign;
%data;
%model;
%report;
%mend orassign;

%orassign;


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

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

Program 2.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 2.3: Using PROC OPTMODEL for Transportation problem;
option nodate ;
%let _title=’Example 2.3: Transshipment problem for two suppliers, two warehouses and two customers.’;
%let _data=’c:\sasor\data2_3.txt’;

* The data handling macro;
%macro data;
* Import text tab delimited data file to SAS data file;
proc import
datafile=&_data
out=dcost
dbms=tab
replace;
getnames=yes;
run;
%mend data;

%macro model;
* Starting OPTMODEL Procedure;
proc optmodel;

* Define sets;
set SUPPLIERS;
set CUSTOMERS={1..4};

* Define parameters;
number demand{CUSTOMERS};
number supply{SUPPLIERS};
number cost{SUPPLIERS, CUSTOMERS};

* Define variables;
var X{SUPPLIERS, CUSTOMERS} >= 0;

* Load the supplier set and their amount of supply;
read data dcost (where= (supply ne .))
into SUPPLIERS=[Supplier] supply[Supplier]=col(“supply”);

* Load the customer set and their demand;
read data dcost (where= (supply eq .)) into
{c in CUSTOMERS} <demand[c]=col(“Cstmer”||c)>;

* Load the cost of shipment from each supplier to each customer;
read data dcost (where= (supply ne .))
into SUPPLIERS=[Supplier]
{c in CUSTOMERS} <cost[Supplier,c]=col(“Cstmer”||c)>;

* Define objective function;
min obj = sum{s in SUPPLIERS, c in CUSTOMERS} cost[s,c]*x[s,c];

* Define constraints;
con req_supply{s in SUPPLIERS}:
sum{c in CUSTOMERS} x[s,c] <= supply[s];

con req_demand{c in CUSTOMERS}:
sum{s in SUPPLIERS} x[s,c] >= demand[c];

con zero{c in CUSTOMERS, s in SUPPLIERS : cost[s,c]=1E10}: x[s,c]=0;

* Solve the model;
solve with lp/solver=primal;

* Create optimum values in a SAS dataset ‘optimout’;
create data optimout
from [SUPPLIERS CUSTOMERS]
={s in SUPPLIERS, c in CUSTOMERS: x[s,c]^=0}
amount=x;

* End of OPTMODEL Procedure;
quit;
%mend model;

* The report writing macro;
%macro report;
* report the results in a tabulated form;
proc tabulate data=optimout;
title &_title;
class SUPPLIERS CUSTOMERS ;
var amount;
table SUPPLIERS =” Suppliers”,
CUSTOMERS*amount*sum
/ BOX=’Amount of suppliers to customers’ ;
run;
%mend report;

* The ortrans macro for transportation problem;

%macro ortrans;
%data;
%model;
%report;
%mend ortrans;

%ortrans;


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

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

Program 3.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.                          *
****************************************************************************/

* SAS procedure for minimum cost flow problem;
option nodate ;
%let _data=’c:/sasor/data3_1.txt’;
%let _title=’Example 3.1. Minimum cost flow problem’;
%let _tail=origin;
%let _head=destination;
%let _cost=cost;
%let _capac=capacity;
%let _demand=demand;
%let _supply=supply;

* The data handling macro;
%macro data;
* Import text tab delimited data file to SAS data file;

proc import
datafile=&_data
out=dcost
dbms=tab
replace;
getnames=yes;
run;

%mend data;
* The model building macro;
%macro model;

proc netflow
arcdata=dcost
arcout=arcout1
nodeout=nodeout1;
tail &_tail;
head &_head;
cost &_cost;
capac &_capac;
demand &_demand;
supply &_supply;
run;

%put &_ORNETFL;
%mend model;

* The report writing macro;
%macro report;
title &_title;
proc print
data=arcout1;
sum _fcost_;
proc print
data=nodeout1;
run;
%mend report;

* A SAS macro for minimum cost capacitated flow problem;

%macro ormcflow;
%data;
%model;
%report;
%mend ormcflow;
%ormcflow;


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

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