<?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 Re: Proc optmodel &amp;quot;by row&amp;quot; (Excel solver) in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864677#M3852</link>
    <description>&lt;P&gt;Here's one way to do it, with a DO loop that calls the solver once for each observation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   set OBS;
   num int {OBS};
   num amt_removed {OBS};
   num i1 {OBS};
   num i2 {OBS};
   num i3 {OBS};
   num b {OBS};
   num c {OBS};
   read data a1 into OBS=[_N_] int amt_removed i1 i2 i3 b c;

   var X;
   num obsThis;
   min error = abs(X*i1[obsThis]-i2[obsThis]-i3[obsThis]+b[obsThis]+c[obsThis]-int[obsThis]);
   num Xsol {OBS};

   do obsThis = OBS;
      put obsThis=;
      solve linearize;
      Xsol[obsThis] = X.sol;
   end;

   create data want from [i] int amt_removed i1 i2 i3 b c X=Xsol;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice that the LINEARIZE option automatically linearizes the absolute value and calls the linear programming (LP) solver.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other approaches include using a FOR loop or COFOR loop.&amp;nbsp; In SAS Optimization in SAS Viya, you can also use the groupBy= parameter in the runOptmodel action to do BY-group processing without writing any explicit loops.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this SAS Usage Note for an example that involves multiple observations per group:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/kb/42/332.html" target="_blank" rel="noopener"&gt;https://support.sas.com/kb/42/332.html&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Mar 2023 20:30:18 GMT</pubDate>
    <dc:creator>RobPratt</dc:creator>
    <dc:date>2023-03-16T20:30:18Z</dc:date>
    <item>
      <title>Proc optmodel "by row" (Excel solver)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864660#M3847</link>
      <description>&lt;P&gt;Hi all -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to get an iterative solution for each observation. The examples I've been through appear to optimize across a dataset (I've never used proc optmodel so I'm pretty ignorant here). My data looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a1;&lt;BR /&gt;input int amt_removed i1 i2 i3 b c;&lt;BR /&gt;datalines;&lt;BR /&gt;0.024860826 5 0.002456519 0.004913037 0.008185046 0.006051554 0.00734217&lt;BR /&gt;0.031408863 1 0.002456519 0.004913037 0.001637009 0.006051554 0.00734217&lt;BR /&gt;0.020765289 3 0.002456519 0.004913037 0.004911028 0.006051554 0.00734217&lt;BR /&gt;0.010037152 1 0.002456519 0.004913037 0.001637009 0.006051554 0.00734217&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I want to find the solution (X) for each observation of this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;min error = abs(X*i1-i2-i3+b+c-int);&lt;/P&gt;&lt;P&gt;or X=(int+i2+i3-b-c)/(i1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thus, the solutions for the four rows are, respectively, X=10, 10, 7, and 1.3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I realize, of course, I can/do solve this analytically in this simple example, but my actual data makes this more complicated and requires an iterative solution. Seems like this should be easy, but I can't seem to figure it out. Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 19:54:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864660#M3847</guid>
      <dc:creator>rj_missionbeach</dc:creator>
      <dc:date>2023-03-16T19:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc optmodel "by row" (Excel solver)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864666#M3848</link>
      <description>&lt;P&gt;So what would PROC OPTMODEL code look like for row 1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps &lt;A href="https://blogs.sas.com/content/sasdummy/2016/02/15/using-proc-iomoperate/" target="_self"&gt;this example&lt;/A&gt; using DOSUBL would apply here, where the author is running some other PROC on each row.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 20:07:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864666#M3848</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-16T20:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: Proc optmodel "by row" (Excel solver)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864669#M3849</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/440903"&gt;@rj_missionbeach&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to get an iterative solution for each observation. The examples I've been through appear to optimize across a dataset (I've never used proc optmodel so I'm pretty ignorant here). My data looks like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a1;&lt;BR /&gt;input int amt_removed i1 i2 i3 b c;&lt;BR /&gt;datalines;&lt;BR /&gt;0.024860826 5 0.002456519 0.004913037 0.008185046 0.006051554 0.00734217&lt;BR /&gt;0.031408863 1 0.002456519 0.004913037 0.001637009 0.006051554 0.00734217&lt;BR /&gt;0.020765289 3 0.002456519 0.004913037 0.004911028 0.006051554 0.00734217&lt;BR /&gt;0.010037152 1 0.002456519 0.004913037 0.001637009 0.006051554 0.00734217&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I want to find the solution (X) for each observation of this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;min error = abs(X*i1-i2-i3+b+c-int);&lt;/P&gt;
&lt;P&gt;or X=(int+i2+i3-b-c)/(i1)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thus, the solutions for the four rows are, respectively, X=10, 10, 7, and 1.3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I realize, of course, I can/do solve this analytically in this simple example, but my actual data makes this more complicated and requires an iterative solution. Seems like this should be easy, but I can't seem to figure it out. Any help would be greatly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;See if this is what you expect:&lt;/P&gt;
&lt;PRE&gt;data a1;
input int amt_removed i1 i2 i3 b c;
X=(int+i2+i3-b-c)/(i1);
datalines;
0.024860826 5 0.002456519 0.004913037 0.008185046 0.006051554 0.00734217
0.031408863 1 0.002456519 0.004913037 0.001637009 0.006051554 0.00734217
0.020765289 3 0.002456519 0.004913037 0.004911028 0.006051554 0.00734217
0.010037152 1 0.002456519 0.004913037 0.001637009 0.006051554 0.00734217
;&lt;/PRE&gt;
&lt;P&gt;The X you provided appear to be rounded results. I get x=9.9999979646 for the first and second observations. So perhaps you would round the value to 1 or 2 decimal places which would be&lt;/P&gt;
&lt;P&gt;round(x,0.1) for 1 decimal place or round(x,0.01) for two decimal places.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 20:12:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864669#M3849</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-16T20:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc optmodel "by row" (Excel solver)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864671#M3850</link>
      <description>&lt;P&gt;Thank you ballardw - I agree that is the analytical solution. However, my real data are more complicated and cannot be solved algebraically. I can solve using excel solver, and am trying to figure out if there is an analogous SAS solution.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 20:19:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864671#M3850</guid>
      <dc:creator>rj_missionbeach</dc:creator>
      <dc:date>2023-03-16T20:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proc optmodel "by row" (Excel solver)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864676#M3851</link>
      <description>&lt;P&gt;Thank you Paige -&lt;/P&gt;&lt;P&gt;I'm new to optmodel so I'm not sure. I simply want sas to, iteratively, solve for X (for each row of data) by finding the X that makes this (approximately) zero:&amp;nbsp;abs(X*i1-i2-i3+b+c-int). I'm not sure optmodel is the solution - I simply googled SAS and excel solver which kept coming up with optmodel.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 20:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864676#M3851</guid>
      <dc:creator>rj_missionbeach</dc:creator>
      <dc:date>2023-03-16T20:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc optmodel "by row" (Excel solver)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864677#M3852</link>
      <description>&lt;P&gt;Here's one way to do it, with a DO loop that calls the solver once for each observation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   set OBS;
   num int {OBS};
   num amt_removed {OBS};
   num i1 {OBS};
   num i2 {OBS};
   num i3 {OBS};
   num b {OBS};
   num c {OBS};
   read data a1 into OBS=[_N_] int amt_removed i1 i2 i3 b c;

   var X;
   num obsThis;
   min error = abs(X*i1[obsThis]-i2[obsThis]-i3[obsThis]+b[obsThis]+c[obsThis]-int[obsThis]);
   num Xsol {OBS};

   do obsThis = OBS;
      put obsThis=;
      solve linearize;
      Xsol[obsThis] = X.sol;
   end;

   create data want from [i] int amt_removed i1 i2 i3 b c X=Xsol;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice that the LINEARIZE option automatically linearizes the absolute value and calls the linear programming (LP) solver.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other approaches include using a FOR loop or COFOR loop.&amp;nbsp; In SAS Optimization in SAS Viya, you can also use the groupBy= parameter in the runOptmodel action to do BY-group processing without writing any explicit loops.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this SAS Usage Note for an example that involves multiple observations per group:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/kb/42/332.html" target="_blank" rel="noopener"&gt;https://support.sas.com/kb/42/332.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 20:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864677#M3852</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2023-03-16T20:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc optmodel "by row" (Excel solver)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864686#M3853</link>
      <description>&lt;P&gt;Thank you Rob -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That seems to work if I comment out the linearize. With linearize in there, I get an error message.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;08 do obsThis = OBS;&lt;BR /&gt;209 put obsThis=;&lt;BR /&gt;210 solve linearize;&lt;BR /&gt;---------&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: /, OBJECTIVE, WITH.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;211 Xsol[obsThis] = X.sol;&lt;BR /&gt;212 end;&lt;BR /&gt;213&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 20:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864686#M3853</guid>
      <dc:creator>rj_missionbeach</dc:creator>
      <dc:date>2023-03-16T20:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc optmodel "by row" (Excel solver)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864691#M3854</link>
      <description>&lt;P&gt;Automated linearization via the LINEARIZE option was introduced in SAS Optimization in the 2020.1.1 release of SAS Viya.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 21:02:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864691#M3854</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2023-03-16T21:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: Proc optmodel "by row" (Excel solver)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864692#M3855</link>
      <description>&lt;P&gt;Thank you Rob!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 21:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Proc-optmodel-quot-by-row-quot-Excel-solver/m-p/864692#M3855</guid>
      <dc:creator>rj_missionbeach</dc:creator>
      <dc:date>2023-03-16T21:09:38Z</dc:date>
    </item>
  </channel>
</rss>

