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

* SAS macro for shortest path problem: solution to exercise 3.6.;
%let _title=’An example of a shortest path network, solution to exercise 3.3′;
%let _data=’c:\sasor\Data3_3_exercise.txt’;
%let _sourcenode=’City1′;
%let _sinknode=’City7′;
%let _cost=cost;
%let _tail=origin;
%let _head=dest;
%option nodate;

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

* The model building macro;
%macro model;
proc netflow
shortpath
sourcenode=&_sourcenode
sinknode=&_sinknode
arcdata=dpath
arcout=arcout1;
cost &_cost;
tail &_tail;
head &_head;
run;
%put &_ORNETFL;
%mend model;

* The report writing macro;
%macro report;
title &_title ‘, how to get from ‘ &_sourcenode ‘ to ‘ &_sinknode ;

* Sort results by origin;
proc sort
data=arcout1
out=result1;
by _fcost_;
run;

* Print results sorted by origin;
proc print
data=result1;
sum _fcost_;
run;

* Sort results by total destination;
proc sort
data=arcout1
out=result2;
by _anumb_;
run;

* Print results sorted by total destination;
proc print
data=result2 (where=(_fcost_ ne 0));
sum _fcost_;
run;
%mend report;

%macro orshortpath;
%data;
%model;
%report;
%mend orshortpath;

%orshortpath;


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

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

Leave a Reply