Using the below code I can calculate absolute error for each month. However, something isn't working when I try to minimize the sum of a created variable, "sae". Effectively, I'm trying to minimize "mae" (which is the average of the "sae" values, excluding the first observation) to find the optimal value for "a".
proc optmodel;
set <str,num> MASTER_DATES;
set MASTER = setof {<i,t> in MASTER_DATES}i;
set NROW = setof {<i,t> in MASTER_DATES}t;
num performance {MASTER_DATES};
num month {MASTER_DATES};
read data example_data1 into MASTER_DATES=[master_nbr nrow] performance month;
num forecast{<i,t> in MASTER_DATES};
num sae{<i,t> in MASTER_DATES};
var a >=0 <=1;
for {<i,t> in MASTER_DATES} do;
if <i,t-1> in MASTER_DATES then
do;
forecast[i,t] = (performance[i,t-1]*a)+((1-a)*forecast[i,t-1]);
sae[i,t] = abs(performance[i,t] - forecast[i,t]);
end;
else
do;
forecast[i,t] = performance[i,t];
sae[i,t] = 0;
end;
end;
min mae = (sum {<i,t> in MASTER_DATES} sae[i,t]) / 10;
solve;
print a;
create data optmodel_outdata from [master_nbr nrow] performance month forecast sae;
quit;
Thanks,
Dan