BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dsklein12
Calcite | Level 5

Piggy backing off my last post titled, "Proc Optmodel - Minimize Mean Absolute Error". I'm adding another constant to smooth for trend, but need to add in another equation. In the below code, I have two implicit variables, b and forecast, that are used to optimize a and y. When I run the code, I get the follow error: "The symbol 'forecast' is unknown. This occurs on the "impvar b" step. How do I make the two implicit variable equations compatible with each other since they need to be equating simultaneously? Thank you.

 

data _null_;
if 0 then set example_data2 nobs=n;
call symputx('nrows',n);
stop;
run;
%put &nrows.;

 

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_data2 into MASTER_DATES=[master_nbr nrow] performance month;

var a >=0 <=1;
var y >=0 <=1;

impvar b{<i,t> in MASTER_DATES} =
if <i,t-1> in MASTER_DATES then ((forecast[i,t] - forecast[i,t-1])* y) + ((1 - y) * b[i,t-1])
else (performance[i,t+(&nrows.-1)] - performance[i,t]) / (&nrows. - 1);

impvar forecast{<i,t> in MASTER_DATES} =
if <i,t-1> in MASTER_DATES then (performance[i,t]*a) + ((1 - a) * (forecast[i,t-1] + b[i,t-1]))
else performance[i,t];

impvar sae{<i,t> in MASTER_DATES} = abs(performance[i,t] - forecast[i,t]);

impvar ape{<i,t> in MASTER_DATES} =
if <i,t-1> in MASTER_DATES then abs(sae[i,t] / performance[i,t])
else 0;

min mae = (sum {<i,t> in MASTER_DATES} sae[i,t]) / (&nrows. -1);

solve;
print a y;

create data optmodel_outdata2 from a y mae;
create data optmodel_outdata from [master_nbr nrow] performance month b forecast sae ape;
quit;

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

Because you cannot have circular references between implicit variables, you should instead use explicit variables and constraints in this case, as follows: 

var b{MASTER_DATES};

var forecast{MASTER_DATES};

con b_con{<i,t> in MASTER_DATES}: b[i,t] =
   if <i,t-1> in MASTER_DATES then ((forecast[i,t] - forecast[i,t-1])* y) + ((1 - y) * b[i,t-1])
   else (performance[i,t+(&nrows.-1)] - performance[i,t]) / (&nrows. - 1);
   
con forecast_con{<i,t> in MASTER_DATES}: forecast[i,t] =
   if <i,t-1> in MASTER_DATES then (performance[i,t]*a) + ((1 - a) * (forecast[i,t-1] + b[i,t-1]))
   else performance[i,t];

View solution in original post

2 REPLIES 2
RobPratt
SAS Super FREQ

Because you cannot have circular references between implicit variables, you should instead use explicit variables and constraints in this case, as follows: 

var b{MASTER_DATES};

var forecast{MASTER_DATES};

con b_con{<i,t> in MASTER_DATES}: b[i,t] =
   if <i,t-1> in MASTER_DATES then ((forecast[i,t] - forecast[i,t-1])* y) + ((1 - y) * b[i,t-1])
   else (performance[i,t+(&nrows.-1)] - performance[i,t]) / (&nrows. - 1);
   
con forecast_con{<i,t> in MASTER_DATES}: forecast[i,t] =
   if <i,t-1> in MASTER_DATES then (performance[i,t]*a) + ((1 - a) * (forecast[i,t-1] + b[i,t-1]))
   else performance[i,t];
dsklein12
Calcite | Level 5
Thanks, Rob. This works great!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Discussion stats
  • 2 replies
  • 1049 views
  • 0 likes
  • 2 in conversation