<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Proc Optmodel - Minimize Mean Absolute Error with two variables in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-Minimize-Mean-Absolute-Error-with-two-variables/m-p/586197#M2860</link>
    <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;if 0 then set example_data2 nobs=n;&lt;BR /&gt;call symputx('nrows',n);&lt;BR /&gt;stop;&lt;BR /&gt;run;&lt;BR /&gt;%put &amp;amp;nrows.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc optmodel;&lt;BR /&gt;set &amp;lt;str,num&amp;gt; MASTER_DATES;&lt;BR /&gt;set MASTER = setof {&amp;lt;i,t&amp;gt; in MASTER_DATES}i;&lt;BR /&gt;set NROW = setof {&amp;lt;i,t&amp;gt; in MASTER_DATES}t;&lt;/P&gt;&lt;P&gt;num performance {MASTER_DATES};&lt;BR /&gt;num month {MASTER_DATES};&lt;/P&gt;&lt;P&gt;read data example_data2 into MASTER_DATES=[master_nbr nrow] performance month;&lt;/P&gt;&lt;P&gt;var a &amp;gt;=0 &amp;lt;=1;&lt;BR /&gt;var y &amp;gt;=0 &amp;lt;=1;&lt;/P&gt;&lt;P&gt;impvar b{&amp;lt;i,t&amp;gt; in MASTER_DATES} =&lt;BR /&gt;if &amp;lt;i,t-1&amp;gt; in MASTER_DATES then ((forecast[i,t] - forecast[i,t-1])* y) + ((1 - y) * b[i,t-1])&lt;BR /&gt;else (performance[i,t+(&amp;amp;nrows.-1)] - performance[i,t]) / (&amp;amp;nrows. - 1);&lt;/P&gt;&lt;P&gt;impvar forecast{&amp;lt;i,t&amp;gt; in MASTER_DATES} =&lt;BR /&gt;if &amp;lt;i,t-1&amp;gt; in MASTER_DATES then (performance[i,t]*a) + ((1 - a) * (forecast[i,t-1] + b[i,t-1]))&lt;BR /&gt;else performance[i,t];&lt;/P&gt;&lt;P&gt;impvar sae{&amp;lt;i,t&amp;gt; in MASTER_DATES} = abs(performance[i,t] - forecast[i,t]);&lt;/P&gt;&lt;P&gt;impvar ape{&amp;lt;i,t&amp;gt; in MASTER_DATES} =&lt;BR /&gt;if &amp;lt;i,t-1&amp;gt; in MASTER_DATES then abs(sae[i,t] / performance[i,t])&lt;BR /&gt;else 0;&lt;/P&gt;&lt;P&gt;min mae = (sum {&amp;lt;i,t&amp;gt; in MASTER_DATES} sae[i,t]) / (&amp;amp;nrows. -1);&lt;/P&gt;&lt;P&gt;solve;&lt;BR /&gt;print a y;&lt;/P&gt;&lt;P&gt;create data optmodel_outdata2 from a y mae;&lt;BR /&gt;create data optmodel_outdata from [master_nbr nrow] performance month b forecast sae ape;&lt;BR /&gt;quit;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Sep 2019 16:56:57 GMT</pubDate>
    <dc:creator>dsklein12</dc:creator>
    <dc:date>2019-09-04T16:56:57Z</dc:date>
    <item>
      <title>Proc Optmodel - Minimize Mean Absolute Error with two variables</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-Minimize-Mean-Absolute-Error-with-two-variables/m-p/586197#M2860</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;if 0 then set example_data2 nobs=n;&lt;BR /&gt;call symputx('nrows',n);&lt;BR /&gt;stop;&lt;BR /&gt;run;&lt;BR /&gt;%put &amp;amp;nrows.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc optmodel;&lt;BR /&gt;set &amp;lt;str,num&amp;gt; MASTER_DATES;&lt;BR /&gt;set MASTER = setof {&amp;lt;i,t&amp;gt; in MASTER_DATES}i;&lt;BR /&gt;set NROW = setof {&amp;lt;i,t&amp;gt; in MASTER_DATES}t;&lt;/P&gt;&lt;P&gt;num performance {MASTER_DATES};&lt;BR /&gt;num month {MASTER_DATES};&lt;/P&gt;&lt;P&gt;read data example_data2 into MASTER_DATES=[master_nbr nrow] performance month;&lt;/P&gt;&lt;P&gt;var a &amp;gt;=0 &amp;lt;=1;&lt;BR /&gt;var y &amp;gt;=0 &amp;lt;=1;&lt;/P&gt;&lt;P&gt;impvar b{&amp;lt;i,t&amp;gt; in MASTER_DATES} =&lt;BR /&gt;if &amp;lt;i,t-1&amp;gt; in MASTER_DATES then ((forecast[i,t] - forecast[i,t-1])* y) + ((1 - y) * b[i,t-1])&lt;BR /&gt;else (performance[i,t+(&amp;amp;nrows.-1)] - performance[i,t]) / (&amp;amp;nrows. - 1);&lt;/P&gt;&lt;P&gt;impvar forecast{&amp;lt;i,t&amp;gt; in MASTER_DATES} =&lt;BR /&gt;if &amp;lt;i,t-1&amp;gt; in MASTER_DATES then (performance[i,t]*a) + ((1 - a) * (forecast[i,t-1] + b[i,t-1]))&lt;BR /&gt;else performance[i,t];&lt;/P&gt;&lt;P&gt;impvar sae{&amp;lt;i,t&amp;gt; in MASTER_DATES} = abs(performance[i,t] - forecast[i,t]);&lt;/P&gt;&lt;P&gt;impvar ape{&amp;lt;i,t&amp;gt; in MASTER_DATES} =&lt;BR /&gt;if &amp;lt;i,t-1&amp;gt; in MASTER_DATES then abs(sae[i,t] / performance[i,t])&lt;BR /&gt;else 0;&lt;/P&gt;&lt;P&gt;min mae = (sum {&amp;lt;i,t&amp;gt; in MASTER_DATES} sae[i,t]) / (&amp;amp;nrows. -1);&lt;/P&gt;&lt;P&gt;solve;&lt;BR /&gt;print a y;&lt;/P&gt;&lt;P&gt;create data optmodel_outdata2 from a y mae;&lt;BR /&gt;create data optmodel_outdata from [master_nbr nrow] performance month b forecast sae ape;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 16:56:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-Minimize-Mean-Absolute-Error-with-two-variables/m-p/586197#M2860</guid>
      <dc:creator>dsklein12</dc:creator>
      <dc:date>2019-09-04T16:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Optmodel - Minimize Mean Absolute Error with two variables</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-Minimize-Mean-Absolute-Error-with-two-variables/m-p/586207#M2861</link>
      <description>&lt;P&gt;Because you cannot have circular references between implicit variables, you should instead use explicit variables and constraints in this case, as follows:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var b{MASTER_DATES};

var forecast{MASTER_DATES};

con b_con{&amp;lt;i,t&amp;gt; in MASTER_DATES}: b[i,t] =
   if &amp;lt;i,t-1&amp;gt; in MASTER_DATES then ((forecast[i,t] - forecast[i,t-1])* y) + ((1 - y) * b[i,t-1])
   else (performance[i,t+(&amp;amp;nrows.-1)] - performance[i,t]) / (&amp;amp;nrows. - 1);
   
con forecast_con{&amp;lt;i,t&amp;gt; in MASTER_DATES}: forecast[i,t] =
   if &amp;lt;i,t-1&amp;gt; in MASTER_DATES then (performance[i,t]*a) + ((1 - a) * (forecast[i,t-1] + b[i,t-1]))
   else performance[i,t];&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Sep 2019 17:39:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-Minimize-Mean-Absolute-Error-with-two-variables/m-p/586207#M2861</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2019-09-04T17:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Optmodel - Minimize Mean Absolute Error with two variables</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-Minimize-Mean-Absolute-Error-with-two-variables/m-p/586428#M2863</link>
      <description>Thanks, Rob. This works great!</description>
      <pubDate>Thu, 05 Sep 2019 14:14:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-Optmodel-Minimize-Mean-Absolute-Error-with-two-variables/m-p/586428#M2863</guid>
      <dc:creator>dsklein12</dc:creator>
      <dc:date>2019-09-05T14:14:15Z</dc:date>
    </item>
  </channel>
</rss>

