BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Zakir
Obsidian | Level 7

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="&region")) 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;

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

Your CREATE DATA statement does not include year and region and also gets overwritten each time you call the macro.  The following code does what I think you want:

/*      create data efficiency_data from [garage] garage_name efficiency_number ;*/
      create data efficiency_data from [garage] year=&year region="&region" garage_name efficiency_number ;
   quit;

   proc append base=efficiency_data_all data=efficiency_data;
   run;
%mend;

See SAS Help Center: Efficiency Analysis: How to Use Data Envelopment Analysis to Compare Efficiencies o... for a related documentation example.

 

In SAS Viya, you can instead use the groupBy= parameter in the runOptmodel action to automate the BY-group processing:

SAS Help Center: BY-Group Processing 

View solution in original post

2 REPLIES 2
RobPratt
SAS Super FREQ

Your CREATE DATA statement does not include year and region and also gets overwritten each time you call the macro.  The following code does what I think you want:

/*      create data efficiency_data from [garage] garage_name efficiency_number ;*/
      create data efficiency_data from [garage] year=&year region="&region" garage_name efficiency_number ;
   quit;

   proc append base=efficiency_data_all data=efficiency_data;
   run;
%mend;

See SAS Help Center: Efficiency Analysis: How to Use Data Envelopment Analysis to Compare Efficiencies o... for a related documentation example.

 

In SAS Viya, you can instead use the groupBy= parameter in the runOptmodel action to automate the BY-group processing:

SAS Help Center: BY-Group Processing 

Zakir
Obsidian | Level 7

Thank you so much, Rob. I greatly appreciate your help. Regards.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 884 views
  • 1 like
  • 2 in conversation