Hi,
I have the following code from this community. When I run the code, it works, but I find that it does not give efficiency scores by year and region. Any help would be greatly appreciated. Thanks.
data inputs; input input $8.; datalines; staff showroom ;
data outputs; input output $10.; datalines; beta_sales profit ;
data garage_data; input garage_name $ year region $ staff showroom alpha_sales beta_sales profit; datalines; Winchester 2020 A 7 8 10 12 8.5 4 2 0.6 1.5 Andover 2020 A 6 6 20 30 9 4.5 2.3 0.7 1.6 Basingstoke 2020 B 2 3 40 40 2 1.5 0.8 0.25 0.5 Poole 2020 B 14 9 20 25 10 6 2.6 0.86 1.9 Winchester 2021 A 10 9 10 10 11 5 2.4 1 2 Andover 2021 A 24 15 15 13 25 19 8 2.6 4.5 Basingstoke 2021 B 6 7 50 40 8.5 3 2.5 0.9 1.6 Poole 2021 B 8 7.5 5 8 9 4 2.1 0.85 2 ;
proc sort data=garage_data; by year region; run;
data garage_data1; set garage_data(keep=year region); by year region; if first.region; run;
%macro compute(year=,region=);
proc optmodel ;
set <str> INPUTS; read data inputs into INPUTS=[input];
set <str> OUTPUTS;
read data outputs into OUTPUTS=[output];
set <num> GARAGES ;
str garage_name {GARAGES}; num input {INPUTS, GARAGES}; num output {OUTPUTS, GARAGES}; read data garage_data(where=(year=&year and region="®ion")) into GARAGES=[_N_] garage_name {i in INPUTS} <input[i,_N_]=col(i)> {i in OUTPUTS} <output[i,_N_]=col(I)>;
num k; num efficiency_number {GARAGES}; num weight_sol {GARAGES, GARAGES};
var Weight {GARAGES} >= 0; var Inefficiency >= 0;
max Objective = Inefficiency;
con Input_con {i in INPUTS}: sum {j in GARAGES} input[i,j] * Weight[j] <= input[i,k];
con Output_con {i in OUTPUTS}: sum {j in GARAGES} output[i,j] * Weight[j] >= output[i,k] * Inefficiency;
do k = GARAGES; solve; efficiency_number[k] = 1 / Inefficiency.sol; for {j in GARAGES} weight_sol[k,j] = (if Weight[j].sol > 1e-6 then Weight[j].sol else .); end;
print garage_name efficiency_number; create data efficiency_data from [garage] garage_name efficiency_number ; quit;
%mend;
data _null_; set garage_data1; call execute(cats('%nrstr(%compute(year=',year,',region=',region,'))')); run;
... View more