/***********************************************************************************
* 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 Ordered Weighted Averaging Operators: solution to exercise 9.1.;
%let _title=’Ordered Weighted Averaging Operators, solution to exercise 9.1′;
option nodate ;
%let _data=’c:/sasor/Data9_1_exercise.txt’;
%let _alpha=0.25;
%let _ncriteria=7;
%let _nalternative=15;
%let _owa1=’c:/sasor/owaOut1.txt’;
%let _owa2=’c:/sasor/owaOut2.txt’;
%let _owaOut1=owaOut1;
%let _owaOut2=owaOut2;
* Import text tab delimited data file to SAS data file;
%macro data;
proc import
datafile=&_data
out=alts
dbms=tab
replace;
getnames=yes;
run;
%mend data;
%macro model;
proc optmodel;
set CRITERIA = 1..&_ncriteria;
set CRITERIA1 = 1..&_ncriteria-1;
set ALTERNATIVE = 1..&_nalternative;
number c{ALTERNATIVE, CRITERIA};
number rankAE{ALTERNATIVE} ;
number rankMIN{ALTERNATIVE} ;
number rankMAX{ALTERNATIVE} ;
number rankMEAN{ALTERNATIVE} ;
number corder{ALTERNATIVE, CRITERIA};
number wMAX{ALTERNATIVE};
number wMIN{ALTERNATIVE};
number wMEAN{ALTERNATIVE};
number ctemp;
number altName{ALTERNATIVE};
number alpha=&_alpha;
number n=&_ncriteria;
var w{CRITERIA} ;
var delta;
read data alts
into [ALTERNATIVE]
{j in CRITERIA} ;
min obj =delta;
con orness: (1/(n-1))* sum{i in CRITERIA} (n-i)*w[i] = alpha;
con wji{i in 1..n, j in i+1..n }:
w[j]-w[i]+delta >= 0;
con wij{i in 1..n, j in i+1..n }:
w[i]-w[j]+delta >= 0;
con swumw:
sum{i in 1..n} w[i]= 1;
solve ;
%report;
quit;
%mend model;
%macro report;
* MAX-OWA;
for {i in CRITERIA}
if i=1 then wMAX[i]=1; else wMAX[i]=0;
* MIN-OWA;
for {i in CRITERIA}
if i=n then wMIN[i]=1; else wMIN[i]=0;
* MEAN-OWA;
for {i in CRITERIA}
wMEAN[i]=1/n;
*Order the criteria;
for {k in ALTERNATIVE}
do;
for {i in CRITERIA}
for {j in CRITERIA}
do;
if c[k,j] do;
ctemp=c[k,i]; c[k,i]=c[k,j];c[k,j]=ctemp;
end;
end;
end;
*Rank by AE-OWA model;
for {k in ALTERNATIVE}
do;
rankAE[k]=0;
for {i in CRITERIA}
rankAE[k]=rankAE[k]+c[k,i]*w[i];
end;
*Rank by MIN-OWA model;
for {k in ALTERNATIVE}
do;
rankMIN[k]=0;
for {i in CRITERIA}
rankMIN[k]=rankMIN[k]+c[k,i]*wMIN[i];
end;
*Rank by MIN-OWA model;
for {k in ALTERNATIVE}
do;
rankMAX[k]=0;
for {i in CRITERIA}
rankMAX[k]=rankMAX[k]+c[k,i]*wMAX[i];
end;
*Rank by MEAN-OWA model;
for {k in ALTERNATIVE}
do;
rankMEAN[k]=0;
for {i in CRITERIA}
rankMEAN[k]=rankMEAN[k]+c[k,i]*wMEAN[i];
end;
* To save the OWA weight in a text file;
file &_owa1;
put ‘Criteria,’ ‘w,’ ‘wMAX,’ ‘wMIN,’ ‘wMEAN’;
for {i in CRITERIA}
do;
put i ‘,’ w[i] ‘,’ wMAX[i] ‘,’ wMIN[i]’,’ wMEAN[i];
end;
* To save the Alternative ranks in a text file;
file &_owa2;
put ‘Alternative,’ ‘rankAE,’ ‘rankMAX,’ ‘rankMIN,’ ‘rankMEAN’;
for {k in ALTERNATIVE}
do;
put k ‘,’ rankAE[k] ‘,’ rankMAX[k] ‘,’ rankMIN[k]’,’ rankMEAN[k];
end;
closefile &_owa1;
closefile &_owa2;
* To save the OWA weight in a SAS dataset;
proc import
datafile=&_owa1
out=&_owaOut1
dbms=csv
replace;
getnames=yes;
run;
proc print; title &_title; run;
* To save the Alternative ranks in a SAS dataset;
proc import
datafile=&_owa2
out=&_owaOut2
dbms=csv
replace;
getnames=yes;
run;
proc print; title &_title; run;
%mend report;
%macro orowa;
%data;
%model;
%mend orwa;
%orowa;
/****************************************************************************
******************************END of the program*****************************
****************************************************************************/