Category: Chapter 9 – Programs

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

*An example of OWA problem in SAS;
option nodate ;
%let _title=’Example 9.1: Ordered Weighted Averaging (OWA) Operators and Preference Ranking’;
%let _data=’c:/sasor/Data9_1.txt’;
%let _alpha=0.3;
%let _ncriteria=6;
%let _nalternative=10;
%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*****************************
****************************************************************************/

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

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


* Using PROC OPTMODEL for Efficiency Measurement with Data Envelopment Analysis (DEA);
option nodate ;
%let _title=’Example 9.2: Efficiency Measurement Using Data Envelopment Analysis (DEA)’;
%let _InData=’C:\sasor\Data9_2_In.txt’;
%let _OutData=’C:\sasor\Data9_2_Out.txt’;
%let _nInput=2;
%let _nOutput=3;
%let _nUnits=10;
%let _Orienta=’OUTPUT’; *alternative option is ‘OUTPUT’ for output orientation;
%let _outdea1=EffOutOri;
%let _outdea2=EffInOri;

/*NOTE to Convexity constraints in both models for VRS;*/

* The data handling macro;
%macro data;
* Import text tab delimited input variables to SAS data file;
proc import
datafile=&_InData
out=data17_input
dbms=tab
replace;
getnames=yes;
run;

* Import text tab delimited output variables to SAS data file;
proc import
datafile=&_OutData
out=data17_output
dbms=tab
replace;
getnames=yes;
run;
%mend data;

* A DEA macro for CRS output orientation;
%macro model_outOri (j0);
* Starting OPTMODEL Procedure;
proc optmodel;
* Define sets;
set INPUTS=1..&_nInput;
set OUTPUTS=1..&_nOutput;
set UNITS=1..&_nUnits;

* Define variables;
var L{UNITS} >=0;
var Sin{INPUTS} >=0 ;
var Sout{OUTPUTS} >=0 ;
var h;

* Define parameters;
number Xin{UNITS, INPUTS};
number Yout{UNITS,OUTPUTS};
string DMUS{UNITS};
number eff;
string DMUj0;

* Load unit names;
read data data17_input
into [_N_]
DMUS[_N_]=col(‘dmu’);


* Load matrix of input variables;
read data data17_input
into [_N_]
{i in INPUTS} ;

* Load matrix of output variables;
read data data17_output
into [_N_]
{r in OUTPUTS} ;

* Define objective function ;
max obj = h;

* Define constrains;
con InpCon_outOri{i in INPUTS}:
sum{j in UNITS} L[j]*Xin[j,i] + Sin[i]=Xin[&j0,i];

con OutCon_outOri{r in OUTPUTS}:
sum{j in UNITS} L[j]*Yout[j,r] – Sout[r]=h*Yout[&j0,r];

* Define convexity constraints for VRS models;
con Convexity: sum{j in UNITS} L[j]=1;

* Solve the model;
solve ;

* Save the efficiency scores in a SAS dataset;
eff=1/h.sol;
DMUj0=DMUS[&j0];
create data solj0 from DMUj0 eff;

*End of PROC OPTMODE;
quit;
%mend model_outOri;

* A DEA macro for CRS input orientation;
%macro model_inOri (j0);
* Starting OPTMODEL Procedure;
proc optmodel;
* Define sets;
set INPUTS=1..&_nInput;
set OUTPUTS=1..&_nOutput;
set UNITS=1..&_nUnits;

* Define variables;
var L{UNITS} >=0;
var Sin{INPUTS} >=0 ;
var Sout{OUTPUTS} >=0 ;
var h;

* Define parameters;
number Xin{UNITS, INPUTS};
number Yout{UNITS,OUTPUTS};
string DMUS{UNITS};
number eff;
string DMUj0;

* Load unit names;
read data data17_input
into [_N_]
DMUS[_N_]=col(‘dmu’);

* Load matrix of input variables;
read data data17_input
into [_N_]
{i in INPUTS} ;

* Load matrix of output variables;
read data data17_output
into [_N_]
{r in OUTPUTS} ;

* Define objective function ;
min obj = h;

* Define constrains;
con InpCon_inOri{i in INPUTS}:
sum{j in UNITS} L[j]*Xin[j,i] + Sin[i]=h*Xin[&j0,i];

con OutCon_inOri{r in OUTPUTS}:
sum{j in UNITS} L[j]*Yout[j,r] – Sout[r]=Yout[&j0,r];

* Define convexity constraints for VRS models;
/*con Convexity: sum{j in UNITS} L[j]=1;*/

* Solve the model;
solve ;

* Save the efficiency scores in a SAS dataset;
eff=h.sol;
DMUj0=DMUS[&j0];
create data solj0 from DMUj0 eff ;

*End of PROC OPTMODE;
quit;
%mend model_inOri;

%macro report;
* Delete previusly created datasets;
proc datasets nolist;
delete &_outdea1 &_outdea2;
run;

* Select the model and execute it for each unit of assessment;
%do j0=1 %to &_nUnits;
%if &_Orienta=”INPUT”
%then %do;
%model_inOri (&j0);
* Save the efficiency scores in a SAS dataset;
proc datasets nolist;
append base=&_outdea2=solj0;
run;
%end;
%else %do;
%model_outOri (&j0);
proc datasets nolist;
append base=&_outdea1 data=solj0;
run;
%end;
%end;

%if &_Orienta=”INPUT”
%then %do;
* Sort and print the results by efficiency score;
proc sort data=&_outdea2;
by eff;
run;
proc print data=&_outdea2;
run;

* Sort and print the results by unit name;
proc sort data=&_outdea2;
by DMUj0;
run;
proc print data=&_outdea2;
run;
%end;
%else %do;
* Sort and print the results by efficiency score;
proc sort data=&_outdea1;
by eff;
run;
proc print data=&_outdea1; title &_title;
run;

* Sort and print the results by unit name;
proc sort data=&_outdea1;
by DMUj0;
run;
proc print data=&_outdea1; title &_title;
run;
%end;

%mend report;

%macro ordea;
%data;
%report;
%mend ordea;

%ordea;


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

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

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


* Using PROC OPTMODEL for Malmquist Productivity Index and its Components;
option nodate ;
%let _title=’Example 9.3. Malmquist Productivity Index and its Components’;
%let _InData_P1=’C:\sasor\Data9_3_In_P1.txt’;
%let _OutData_P1=’C:\sasor\Data9_3_Out_P1.txt’;
%let _InData_P2=’C:\sasor\Data9_3_In_P2.txt’;
%let _OutData_P2=’C:\sasor\Data9_3_Out_P2.txt’;
%let _nInput=2;
%let _nOutput=2;
%let _nUnits=6;
%let _outMalm1=outMalm1;
%let _outMalm2=outMalm2;
%let _Orienta=’INPUTMIN’; * Alternative selection is ‘OUTPUTMAX’;

%macro importdata (txtFile, sasFile);
proc import
datafile=&txtFile
out=&sasFile
dbms=tab
replace;
getnames=yes;
run;
%mend importdata;

* The data handling macro;
%macro data;
* Import text tab delimited input variables to SAS data file, period1;
%importdata(&_InData_P1,data9_3_input_P1);
* Import text tab delimited output variables to SAS data file, period1;
%importdata(&_OutData_P1,data9_3_output_P1);
* Import text tab delimited input variables to SAS data file, period2;
%importdata(&_InData_P2,data9_3_input_P2);
* Import text tab delimited output variables to SAS data file, period2;
%importdata(&_OutData_P2,data9_3_output_P2);
%mend data;

* A DEA macro for CRS output orientation;
%macro model_outOri ( per1, per2,j0);
* Starting OPTMODEL Procedure;
proc optmodel;
* Define sets;
set INPUTS=1..&_nInput;
set OUTPUTS=1..&_nOutput;
set UNITS=1..&_nUnits;
set PERIODS=1..2;

* Define variables;
var L{UNITS} >=0;
var Sin{INPUTS} >=0 ;
var Sout{OUTPUTS} >=0 ;
var h;

* Define parameters;
number Xin{PERIODS,UNITS, INPUTS};
number Yout{PERIODS,UNITS,OUTPUTS};
string DMUS{UNITS};
number eff;
string DMUj0;
number p1;
number p2;

* Load unit names;
read data data9_3_input_P1
into [_N_]
DMUS[_N_]=col(‘dmu’);

* Load matrix of input variables;
read data data9_3_input_P1
into [_N_]
{i in INPUTS} <Xin[1,_N_,i]=col(‘input’||i)>;

* Load matrix of input variables;
read data data9_3_input_P2
into [_N_]
{i in INPUTS} <Xin[2,_N_,i]=col(‘input’||i)>;

* Load matrix of input variables;
read data data9_3_output_P1
into [_N_]
{r in OUTPUTS} <Yout[1,_N_,r]=col(‘output’||r)>;

* Load matrix of input variables;
read data data9_3_output_P2
into [_N_]
{r in OUTPUTS} <Yout[2,_N_,r]=col(‘output’||r)>;

* Define objective function ;
max obj = h;

* Define constrains;
con InpCon_outOri{i in INPUTS}:
sum{j in UNITS} L[j]*Xin[&Per1,j,i] + Sin[i]=Xin[&Per2,&j0,i];

con OutCon_outOri{r in OUTPUTS}:
sum{j in UNITS} L[j]*Yout[&Per1,j,r] – Sout[r]=h*Yout[&Per2,&j0,r];
* Solve the model;
solve ;

* Save the efficiency scores in a SAS dataset;
eff=1/h.sol;
DMUj0=DMUS[&j0];
p1=&Per1;
p2=&Per2;
create data solj0 from DMUj0 p1 p2 eff;

*End of PROC OPTMODE;
quit;
%mend model_outOri;

%macro report(per1,per2);
* Select the model and execute it for each unit of assessment;
%do j0=1 %to &_nUnits;
%model_outOri (&per1,&per2,&j0);
* Save the results for report writing;
proc datasets nolist;
append base=&_outMalm1 data=solj0;
run;
%end;
%mend report;

%macro ormalm;
%data;
* Delete previously created datasets;
proc datasets nolist;
delete &_outMalm1;
run;

%report(1,1);
%report(2,2);
%report(1,2);
%report(2,1);

data &_outMalm2;
merge &_outMalm1(WHERE=(p1=1 and p2=1) RENAME=(eff=DEA11))
&_outMalm1(WHERE=(p1=1 and p2=2) RENAME=(eff=DEA12))
&_outMalm1(WHERE=(p1=2 and p2=1) RENAME=(eff=DEA21))
&_outMalm1(WHERE=(p1=2 and p2=2) RENAME=(eff=DEA22));
by dmuj0;
drop p1 p2;
run;

data &_outMalm2(drop=DEA21 DEA12 rename=(DEA11=EffPeriod1 DEA22=EffPeriod2));
set &_outMalm2;
EffChange=DEA22/DEA11;
TechChange=sqrt((DEA12*DEA11)/(DEA22*DEA21));
MalmIndex=EffChange*TechChange;
run;

proc print; run;

%mend ormalm;

%ormalm;


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

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

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

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

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

* Using PROC OPTMODEL for Efficiency Measurement with Data Envelopment Analysis (DEA): solution to exercise 9.2;
option nodate ;
%let _title=’Efficiency Measurement Using Data Envelopment Analysis (DEA): solution to exercise 9.2′;
%let _InData=’C:\sasor\Data9_2_In_exercise.txt’;
%let _OutData=’C:\sasor\Data9_2_Out_exercise.txt’;
%let _nInput=3;
%let _nOutput=2;
%let _nUnits=20;
%let _Orienta=’OUTPUT’; *alternative option is ‘OUTPUT’ for output orientation;
%let _outdea1=EffOutOri;
%let _outdea2=EffInOri;

/*NOTE to Convexity constraints in both models for VRS;*/

* The data handling macro;
%macro data;
* Import text tab delimited input variables to SAS data file;
proc import
datafile=&_InData
out=data17_input
dbms=tab
replace;
getnames=yes;
run;
* Import text tab delimited output variables to SAS data file;
proc import
datafile=&_OutData
out=data17_output
dbms=tab
replace;
getnames=yes;
run;
%mend data;

* A DEA macro for CRS output orientation;
%macro model_outOri (j0);
* Starting OPTMODEL Procedure;
proc optmodel;
* Define sets;
set INPUTS=1..&_nInput;
set OUTPUTS=1..&_nOutput;
set UNITS=1..&_nUnits;

* Define variables;
var L{UNITS} >=0;
var Sin{INPUTS} >=0 ;
var Sout{OUTPUTS} >=0 ;
var h;

* Define parameters;
number Xin{UNITS, INPUTS};
number Yout{UNITS,OUTPUTS};
string DMUS{UNITS};
number eff;
string DMUj0;

* Load unit names;
read data data17_input
into [_N_]
DMUS[_N_]=col(‘dmu’);

* Load matrix of input variables;
read data data17_input
into [_N_]
{i in INPUTS} <Xin[_N_,i]=col(‘input’||i)>;

* Load matrix of output variables;
read data data17_output
into [_N_]
{r in OUTPUTS} <Yout[_N_,r]=col(‘output’||r)>;

* Define objective function ;
max obj = h;

* Define constrains;
con InpCon_outOri{i in INPUTS}:
sum{j in UNITS} L[j]*Xin[j,i] + Sin[i]=Xin[&j0,i];

con OutCon_outOri{r in OUTPUTS}:
sum{j in UNITS} L[j]*Yout[j,r] – Sout[r]=h*Yout[&j0,r];

* Define convexity constraints for VRS models;
/* con Convexity: sum{j in UNITS} L[j]=1; */

* Solve the model;
solve ;

* Save the efficiency scores in a SAS dataset;
eff=1/h.sol;
DMUj0=DMUS[&j0];
create data solj0 from DMUj0 eff;

*End of PROC OPTMODE;
quit;
%mend model_outOri;

* A DEA macro for CRS input orientation;
%macro model_inOri (j0);


* Starting OPTMODEL Procedure;
proc optmodel;
* Define sets;
set INPUTS=1..&_nInput;
set OUTPUTS=1..&_nOutput;
set UNITS=1..&_nUnits;

* Define variables;
var L{UNITS} >=0;
var Sin{INPUTS} >=0 ;
var Sout{OUTPUTS} >=0 ;
var h;

* Define parameters;
number Xin{UNITS, INPUTS};
number Yout{UNITS,OUTPUTS};
string DMUS{UNITS};
number eff;
string DMUj0;

* Load unit names;
read data data17_input
into [_N_]
DMUS[_N_]=col(‘dmu’);

* Load matrix of input variables;
read data data17_input
into [_N_]
{i in INPUTS} <Xin[_N_,i]=col(‘input’||i)>;

* Load matrix of output variables;
read data data17_output
into [_N_]
{r in OUTPUTS} <Yout[_N_,r]=col(‘output’||r)>;

* Define objective function ;
min obj = h;

* Define constrains;
con InpCon_inOri{i in INPUTS}:
sum{j in UNITS} L[j]*Xin[j,i] + Sin[i]=h*Xin[&j0,i];

con OutCon_inOri{r in OUTPUTS}:
sum{j in UNITS} L[j]*Yout[j,r] – Sout[r]=Yout[&j0,r];

* Define convexity constraints for VRS models;
/*con Convexity: sum{j in UNITS} L[j]=1;*/

* Solve the model;
solve ;

* Save the efficiency scores in a SAS dataset;
eff=h.sol;
DMUj0=DMUS[&j0];
create data solj0 from DMUj0 eff ;


*End of PROC OPTMODE;
quit;
%mend model_inOri;

%macro report;
* Delete previusly created datasets;
proc datasets nolist;
delete &_outdea1 &_outdea2;
run;

* Select the model and execute it for each unit of assessment;
%do j0=1 %to &_nUnits;
%if &_Orienta=”INPUT”
%then %do;
%model_inOri (&j0);
* Save the efficiency scores in a SAS dataset;
proc datasets nolist;
append base=&_outdea2=solj0;
run;
%end;
%else %do;
%model_outOri (&j0);
proc datasets nolist;
append base=&_outdea1 data=solj0;
run;
%end;
%end;

%if &_Orienta=”INPUT”
%then %do;
* Sort and print the results by efficiency score;
proc sort data=&_outdea2;
by eff;
run;
proc print data=&_outdea2;
run;

* Sort and print the results by unit name;
proc sort data=&_outdea2;
by DMUj0;
run;
proc print data=&_outdea2;
run;
%end;
%else %do;
* Sort and print the results by efficiency score;
proc sort data=&_outdea1;
by eff;
run;
proc print data=&_outdea1; title &_title;
run;

* Sort and print the results by unit name;
proc sort data=&_outdea1;
by DMUj0;
run;
proc print data=&_outdea1; title &_title;
run;
%end;

%mend report;

%macro ordea;
%data;
%report;
%mend ordea;

%ordea;


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

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

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

* Using PROC OPTMODEL for Malmquist Productivity Index and its Components: solution to exercise 9.3;
option nodate ;
%let _title=’Malmquist Productivity Index and its Components: solution to exercise 9.3′;
%let _InData_P1=’C:\sasor\Data9_3_In_P1_exercise.txt’;
%let _OutData_P1=’C:\sasor\Data9_3_Out_P1_exercise.txt’;
%let _InData_P2=’C:\sasor\Data9_3_In_P2_exercise.txt’;
%let _OutData_P2=’C:\sasor\Data9_3_Out_P2_exercise.txt’;
%let _nInput=2;
%let _nOutput=2;
%let _nUnits=10;
%let _outMalm1=outMalm1;
%let _outMalm2=outMalm2;
%let _Orienta=’INPUTMIN’; * Alternative selection is ‘OUTPUTMAX’;

%macro importdata (txtFile, sasFile);
proc import
datafile=&txtFile
out=&sasFile
dbms=tab
replace;
getnames=yes;
run;
%mend importdata;

* The data handling macro;
%macro data;
* Import text tab delimited input variables to SAS data file, period1;
%importdata(&_InData_P1,data9_3_input_P1);
* Import text tab delimited output variables to SAS data file, period1;
%importdata(&_OutData_P1,data9_3_output_P1);
* Import text tab delimited input variables to SAS data file, period2;
%importdata(&_InData_P2,data9_3_input_P2);
* Import text tab delimited output variables to SAS data file, period2;
%importdata(&_OutData_P2,data9_3_output_P2);
%mend data;

* A DEA macro for CRS output orientation;
%macro model_outOri ( per1, per2,j0);
* Starting OPTMODEL Procedure;
proc optmodel;
* Define sets;
set INPUTS=1..&_nInput;
set OUTPUTS=1..&_nOutput;
set UNITS=1..&_nUnits;
set PERIODS=1..2;

* Define variables;
var L{UNITS} >=0;
var Sin{INPUTS} >=0 ;
var Sout{OUTPUTS} >=0 ;
var h;

* Define parameters;
number Xin{PERIODS,UNITS, INPUTS};
number Yout{PERIODS,UNITS,OUTPUTS};
string DMUS{UNITS};
number eff;
string DMUj0;
number p1;
number p2;

* Load unit names;
read data data9_3_input_P1
into [_N_]
DMUS[_N_]=col(‘dmu’);

* Load matrix of input variables;
read data data9_3_input_P1
into [_N_]
{i in INPUTS} ;

* Load matrix of input variables;
read data data9_3_input_P2
into [_N_]
{i in INPUTS} ;

* Load matrix of input variables;
read data data9_3_output_P1
into [_N_]
{r in OUTPUTS} ;

* Load matrix of input variables;
read data data9_3_output_P2
into [_N_]
{r in OUTPUTS} ;

* Define objective function ;
max obj = h;

* Define constrains;
con InpCon_outOri{i in INPUTS}:
sum{j in UNITS} L[j]*Xin[&Per1,j,i] + Sin[i]=Xin[&Per2,&j0,i];

con OutCon_outOri{r in OUTPUTS}:
sum{j in UNITS} L[j]*Yout[&Per1,j,r] – Sout[r]=h*Yout[&Per2,&j0,r];
* Solve the model;
solve ;

* Save the efficiency scores in a SAS dataset;
eff=1/h.sol;
DMUj0=DMUS[&j0];
p1=&Per1;
p2=&Per2;
create data solj0 from DMUj0 p1 p2 eff;

*End of PROC OPTMODE;
quit;
%mend model_outOri;

%macro report(per1,per2);
* Select the model and execute it for each unit of assessment;
%do j0=1 %to &_nUnits;
%model_outOri (&per1,&per2,&j0);
* Save the results for report writing;
proc datasets nolist;
append base=&_outMalm1 data=solj0;
run;
%end;
%mend report;

%macro ormalm;
%data;
* Delete previously created datasets;
proc datasets nolist;
delete &_outMalm1;
run;

%report(1,1);
%report(2,2);
%report(1,2);
%report(2,1);

data &_outMalm2;
merge &_outMalm1(WHERE=(p1=1 and p2=1) RENAME=(eff=DEA11))
&_outMalm1(WHERE=(p1=1 and p2=2) RENAME=(eff=DEA12))
&_outMalm1(WHERE=(p1=2 and p2=1) RENAME=(eff=DEA21))
&_outMalm1(WHERE=(p1=2 and p2=2) RENAME=(eff=DEA22));
by dmuj0;
drop p1 p2;
run;

data &_outMalm2(drop=DEA21 DEA12 rename=(DEA11=EffPeriod1 DEA22=EffPeriod2));
set &_outMalm2;
EffChange=DEA22/DEA11;
TechChange=sqrt((DEA12*DEA11)/(DEA22*DEA21));
MalmIndex=EffChange*TechChange;
run;

proc print; run;

%mend ormalm;

%ormalm;


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

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