<?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: Minimize Function with Opt Model in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959145#M4263</link>
    <description>&lt;P&gt;I don't want to find the betas, I already have the beta values. I would like to find the a, b, c , d , e values in an interval from my dataset or an interval that I will determine to minimize the y value. It's just an equation where my betas can be positive or negatives.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Feb 2025 07:50:56 GMT</pubDate>
    <dc:creator>harmonic</dc:creator>
    <dc:date>2025-02-13T07:50:56Z</dc:date>
    <item>
      <title>Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959022#M4259</link>
      <description>&lt;P&gt;Hello community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am starting using Proc Opt model, and I would like to minimize a function like this one:&lt;BR /&gt;&lt;BR /&gt;min|y|=B1*type + B2*b + B3*c +&amp;nbsp; B4*d + B5*e + B6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where values are taken from a dataset, here the values:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Y should be an integer number and this is the distribution&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="harmonic_0-1739351362386.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104560i903D0127B771FFC7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="harmonic_0-1739351362386.png" alt="harmonic_0-1739351362386.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;B1, B2, B3, B4, B5 and B6 are constants&lt;BR /&gt;&lt;BR /&gt;'type' should be a string with values "white", "black"&lt;/P&gt;
&lt;P&gt;Should I have different results for each string?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;'b' should be with values 2 and 12&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'c' should be in a float value in this distribution&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="harmonic_1-1739351596501.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104561iA1DE8D569E09D6D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="harmonic_1-1739351596501.png" alt="harmonic_1-1739351596501.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'d'&amp;nbsp;should be in an interval 1 to 48 integer values&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'e' should be with values 0, 2 or 12&lt;BR /&gt;&lt;BR /&gt;Thank you in advance&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 09:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959022#M4259</guid>
      <dc:creator>harmonic</dc:creator>
      <dc:date>2025-02-12T09:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959092#M4260</link>
      <description>&lt;P&gt;I don't quite understand your problem.&amp;nbsp; Do you want to solve a regression problem where b, c, d, and e are regression coefficients?&amp;nbsp; If B1 is a constant and type is a string, what does B1*type mean?&amp;nbsp; Are you able to share example data and also an example (not necessarily optimal) solution?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 18:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959092#M4260</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2025-02-12T18:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959093#M4261</link>
      <description>&lt;P data-start="60" data-end="66"&gt;Yes,&lt;/P&gt;
&lt;P data-start="68" data-end="391"&gt;For example, I would like to minimize &lt;STRONG data-start="106" data-end="111"&gt;y&lt;/STRONG&gt; in this dataset. I was planning to set a lower limit of &lt;STRONG data-start="168" data-end="173"&gt;y&lt;/STRONG&gt; to 1 because I don’t want it to be zero, and I also need to include constraints that are not explicitly visible in my data. For instance, the values in column &lt;STRONG data-start="333" data-end="340"&gt;'a'&lt;/STRONG&gt; should be within the integer range from 6 to 48.&lt;/P&gt;
&lt;P data-start="393" data-end="568"&gt;Could you provide an example of how to minimize a regression function for &lt;STRONG data-start="467" data-end="472"&gt;y&lt;/STRONG&gt; using this dataset or by applying the constraints I want, instead of using one of my columns?&lt;/P&gt;
&lt;P data-start="570" data-end="727"&gt;&lt;STRONG data-start="570" data-end="578"&gt;Type&lt;/STRONG&gt; is an example of a string column where I should perform minimization for each string value, but for now, we can ignore it to simplify the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 19:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959093#M4261</guid>
      <dc:creator>harmonic</dc:creator>
      <dc:date>2025-02-12T19:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959098#M4262</link>
      <description>&lt;P&gt;The following PROC OPTMODEL code solves an ordinary least squares regression:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   /* declare sets and input parameters */
   set OBS;
   num y {OBS};
   num a {OBS};
   num b {OBS};
   num c {OBS};
   num d {OBS};
   num e {OBS};

   /* read input data set */
   read data input into OBS=[_N_] y a b c d e;

   /* declare decision variables */
   var Beta {0..5};
   var Error {OBS};
   impvar Estimate {i in OBS} = Beta[0] + Beta[1]*a[i] + Beta[2]*b[i] + Beta[3]*c[i] + Beta[4]*d[i] + Beta[5]*e[i];

   /* declare objective to minimize sum of squared errors */
   min SSE = sum {i in OBS} Error[i]^2;

   /* declare constraints */
   con ErrorCon {i in OBS}:
      Error[i] = Estimate[i] - y[i];

   /* call quadratic programming (QP) solver */
   solve;

   /* print regression coefficients */
   print Beta;

   /* create output data sets */
   create data BetaData from [j] Beta;
   create data EstimateData from [i] a b c d e y Estimate Error;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The resulting regression coefficients are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: Beta" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l b header" scope="col"&gt;[1]&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Beta&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;0&lt;/TH&gt;
&lt;TD class="r data"&gt;416.9191&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;19.3854&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;18.5124&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;-13.0827&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;-22.7077&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;-1.4499&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="branch"&gt;Those are the same values that are returned by the following PROC REG call:&lt;/DIV&gt;
&lt;DIV class="branch"&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc reg data=input;
   model y = a b c d e;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV class="branch"&gt;For the additional constraints, do you want to impose bounds on Beta[j]?&lt;/DIV&gt;
&lt;DIV class="branch"&gt;Or do you instead want to solve an optimization problem where a, b, c, d, and e are the (bounded) decision variables and you want to minimize the predicted value of y?&amp;nbsp; That is, with the fixed values of Beta[j] found earlier, do you want to minimize the linear function&amp;nbsp;Beta[0] + Beta[1]*a + Beta[2]*b + Beta[3]*c + Beta[4]*d + Beta[5]*e subject to some constraints on a, b, c, d, and e?&lt;/DIV&gt;</description>
      <pubDate>Wed, 12 Feb 2025 20:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959098#M4262</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2025-02-12T20:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959145#M4263</link>
      <description>&lt;P&gt;I don't want to find the betas, I already have the beta values. I would like to find the a, b, c , d , e values in an interval from my dataset or an interval that I will determine to minimize the y value. It's just an equation where my betas can be positive or negatives.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 07:50:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959145#M4263</guid>
      <dc:creator>harmonic</dc:creator>
      <dc:date>2025-02-13T07:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959155#M4264</link>
      <description>&lt;P&gt;If I understood what you mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
num a{1..2}=[2 12];
num b{1..3}=[2 12 24];
num d{i in 1..10}=i;
num e{i in 1..47}=i;
var var_a{1..2} binary;
var var_b{1..3} binary;
var var_c &amp;gt;=5 &amp;lt;=15;
var var_d{1..10} binary;
var var_e{1..47} binary;
impvar sum=-8*sum{i in 1..2} a[i]*var_a[i] +
           -2*sum{i in 1..3} b[i]*var_b[i] +
	       -2*var_c +
	       -4*sum{i in 1..10}d[i]*var_d[i] +
            2*sum{i in 1..47}e[i]*var_e[i] ;
min obj=sum;
con con_total:sum&amp;gt;=1;
con con_a:sum{i in 1..2} var_a[i]=1;
con con_b:sum{i in 1..3} var_b[i]=1;
con con_d:sum{i in 1..10}var_d[i]=1;
con con_e:sum{i in 1..47}var_e[i]=1;

solve ;

print a var_a ; 
print b var_b ;
print   var_c ;
print d var_d ;
print e var_e ;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1739438064032.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104599i7E152A632D99C3DB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1739438064032.png" alt="Ksharp_0-1739438064032.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_1-1739438098006.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104600i7584468AB4C6D432/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_1-1739438098006.png" alt="Ksharp_1-1739438098006.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_2-1739438135663.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104601i08C6CA87A301BB0B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_2-1739438135663.png" alt="Ksharp_2-1739438135663.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 09:15:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959155#M4264</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-02-13T09:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959189#M4265</link>
      <description>&lt;P&gt;Thanks for posting this reply.&amp;nbsp; +1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A slight improvement is that for variables d and e with consecutive integer domains, you can avoid num d, num e, con_d, and con_e by using integer variables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   var var_d &amp;gt;= 1 &amp;lt;= 10 integer;
   var var_e &amp;gt;= 1 &amp;lt;= 47 integer;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Feb 2025 15:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959189#M4265</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2025-02-13T15:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959190#M4266</link>
      <description>&lt;P&gt;Thank you, I will try by today and tomorrow if it is work. If I would like to&amp;nbsp;use steps of 4 within the interval? How can i change it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 15:40:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959190#M4266</guid>
      <dc:creator>harmonic</dc:creator>
      <dc:date>2025-02-13T15:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959191#M4267</link>
      <description>&lt;P&gt;If I would like to read the data from my dataset?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 16:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959191#M4267</guid>
      <dc:creator>harmonic</dc:creator>
      <dc:date>2025-02-13T16:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959207#M4268</link>
      <description>&lt;P&gt;Here's one way to enforce that x is in {2,6,10,...,42}:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   var x;
   set MYSET = 2..42 by 4;
   var y {MYSET} binary;
   con Mycon1: sum {i in MYSET} y[i] = 1;
   con Mycon2:&amp;nbsp;sum {i in MYSET} i*y[i] = x;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here's another way that uses fewer variables and constraints:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   var x &amp;gt;= 2 &amp;lt;= 42;
   var y integer;
   con Mycon: x = 2 + 4*y;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See also&amp;nbsp;&lt;A href="https://or.stackexchange.com/questions/6545/how-to-linearize-membership-in-a-finite-set" target="_blank" rel="noopener"&gt;https://or.stackexchange.com/questions/6545/how-to-linearize-membership-in-a-finite-set&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 18:34:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959207#M4268</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2025-02-13T18:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959235#M4269</link>
      <description>&lt;P&gt;I don't understand. If you want to import these interval of variable from XLSX, you could make a macro variable (assuming the levels of these variable was not too many).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile="C:\Users\xiakeshan\Downloads\input.xlsx" out=have dbms=xlsx replace;
run;
proc sql noprint;
select distinct a into :a separated by ' ' from have;
select count(distinct a) into :_a separated by ' ' from have;

select distinct b into :b separated by ' ' from have;
select count(distinct b) into :_b separated by ' ' from have;

select floor(min(c)) into :min_c from have;
select ceil(max(c)) into :max_c from have;

select distinct d into :d separated by ' ' from have;
select count(distinct d) into :_d separated by ' ' from have;

select distinct e into :e separated by ' ' from have;
select count(distinct e) into :_e separated by ' ' from have;

quit;

proc optmodel;
num a{1..&amp;amp;_a.}=[&amp;amp;a.];
num b{1..&amp;amp;_b.}=[&amp;amp;b.];
num d{1..&amp;amp;_d.}=[&amp;amp;d.];
num e{1..&amp;amp;_e.}=[&amp;amp;e.];
var var_a{1..&amp;amp;_a.} binary;
var var_b{1..&amp;amp;_b.} binary;
var var_c &amp;gt;=&amp;amp;min_c.  &amp;lt;=&amp;amp;max_c.;
var var_d{1..&amp;amp;_d.} binary;
var var_e{1..&amp;amp;_e.} binary;
impvar sum=-8*sum{i in 1..&amp;amp;_a.} a[i]*var_a[i] +
           -2*sum{i in 1..&amp;amp;_b.} b[i]*var_b[i] +
	       -2*var_c +
	       -4*sum{i in 1..&amp;amp;_d.}d[i]*var_d[i] +
            2*sum{i in 1..&amp;amp;_e.}e[i]*var_e[i] ;
min obj=sum;
con con_total:sum&amp;gt;=1;
con con_a:sum{i in 1..&amp;amp;_a.} var_a[i]=1;
con con_b:sum{i in 1..&amp;amp;_b.} var_b[i]=1;
con con_d:sum{i in 1..&amp;amp;_d.} var_d[i]=1;
con con_e:sum{i in 1..&amp;amp;_e.} var_e[i]=1;

solve ;

print a var_a ; 
print b var_b ;
print   var_c ;
print d var_d ;
print e var_e ;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Feb 2025 01:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959235#M4269</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-02-14T01:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959239#M4270</link>
      <description>&lt;P&gt;Yes but I would like to use the read data after I imported my xlsx, is that possible?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2025 08:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959239#M4270</guid>
      <dc:creator>harmonic</dc:creator>
      <dc:date>2025-02-14T08:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959241#M4272</link>
      <description>&lt;P&gt;Sure. the Warning message in LOG you can ignore , since it has nothing to do with optimal problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile="C:\Users\xiakeshan\Downloads\input.xlsx" out=have dbms=xlsx replace;
run;

proc optmodel ;
set a ;
num a1{i in a}=i;
set b;
num b1{i in b}=i;
set c;
set d;
num d1{i in d}=i;
set e;
num e1{i in e}=i;

read data have into a=[a] ;
read data have into b=[b] ;
read data have into c=[c] ;
read data have into d=[d] ;
read data have into e=[e] ;
num min_c=min{i in c} i;
num max_c=max{i in c} i;

var var_a{a} binary;
var var_b{b} binary;
var var_c &amp;gt;=min_c  &amp;lt;=max_c;
var var_d{d} binary;
var var_e{e} binary;

impvar sum=-8*sum{_a in a} _a*var_a[_a] +
           -2*sum{_b in b} _b*var_b[_b] +
	       -2*var_c +
	       -4*sum{_d in d} _d*var_d[_d] +
            2*sum{_e in e} _e*var_e[_e] ;
min obj=sum;
con con_total:sum&amp;gt;=1;
con con_a:sum{i in a} var_a[i]=1;
con con_b:sum{i in b} var_b[i]=1;
con con_d:sum{i in d} var_d[i]=1;
con con_e:sum{i in e} var_e[i]=1;

solve ;

print a1 var_a ; 
print b1 var_b ;
print   var_c ;
print d1 var_d ;
print e1 var_e ;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Feb 2025 09:12:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959241#M4272</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-02-14T09:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959243#M4273</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;, just to add more complexity, if I have a categorical variable in my table, for instance in the variable "e" is a string, can I minimize the function group by string variable? An optimization for each category.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2025 09:24:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959243#M4273</guid>
      <dc:creator>harmonic</dc:creator>
      <dc:date>2025-02-14T09:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959283#M4274</link>
      <description>&lt;P&gt;If you want to process the data like BY statement of PROC .&lt;BR /&gt;The most simple way is spliting this data into many sub-dataset and&lt;STRONG&gt; make a macro to&lt;/STRONG&gt; run the code separatedly.&lt;BR /&gt;If you want more sophisticated method, I think &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt; would help you .&lt;/P&gt;</description>
      <pubDate>Sat, 15 Feb 2025 01:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959283#M4274</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-02-15T01:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959479#M4275</link>
      <description>&lt;P&gt;&lt;SPAN&gt;How can I integrate that in the code of the proc optmodel above?&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 13:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959479#M4275</guid>
      <dc:creator>harmonic</dc:creator>
      <dc:date>2025-02-18T13:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959487#M4277</link>
      <description>&lt;P&gt;Here are a few ways to implement BY-group processing:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/kb/42/332.html" target="_blank"&gt;https://support.sas.com/kb/42/332.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 15:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959487#M4277</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2025-02-18T15:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959502#M4278</link>
      <description>Sorry, this thread is getting hard to follow.  What do you want to integrate into which PROC OPTMODEL code?</description>
      <pubDate>Tue, 18 Feb 2025 16:45:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959502#M4278</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2025-02-18T16:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959565#M4279</link>
      <description>&lt;P&gt;How can I insert these con&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   var x &amp;gt;= 2 &amp;lt;= 42;
   var y integer;
   con Mycon: x = 2 + 4*y;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;to this proc opt model&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
num a{1..2}=[2 12];
num b{1..3}=[2 12 24];
num d{i in 1..10}=i;
num e{i in 1..47}=i;
var var_a{1..2} binary;
var var_b{1..3} binary;
var var_c &amp;gt;=5 &amp;lt;=15;
var var_d{1..10} binary;
var var_e{1..47} binary;
impvar sum=-8*sum{i in 1..2} a[i]*var_a[i] +
           -2*sum{i in 1..3} b[i]*var_b[i] +
	       -2*var_c +
	       -4*sum{i in 1..10}d[i]*var_d[i] +
            2*sum{i in 1..47}e[i]*var_e[i] ;
min obj=sum;
con con_total:sum&amp;gt;=1;
con con_a:sum{i in 1..2} var_a[i]=1;
con con_b:sum{i in 1..3} var_b[i]=1;
con con_d:sum{i in 1..10}var_d[i]=1;
con con_e:sum{i in 1..47}var_e[i]=1;

solve ;

print a var_a ; 
print b var_b ;
print   var_c ;
print d var_d ;
print e var_e ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 08:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959565#M4279</guid>
      <dc:creator>harmonic</dc:creator>
      <dc:date>2025-02-19T08:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: Minimize Function with Opt Model</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959572#M4280</link>
      <description>&lt;PRE&gt;proc optmodel;
num a{1..2}=[2 12];
num b{1..3}=[2 12 24];
num d{i in 1..10}=i;
num e{i in 1..47}=i;
var var_a{1..2} binary;
var var_b{1..3} binary;
&lt;STRONG&gt;var var_c &amp;gt;=2 &amp;lt;=42 ;
var var_d integer;&lt;/STRONG&gt;
impvar sum= 4*sum{i in 1..2} a[i]*var_a[i] +
           -2*sum{i in 1..3} b[i]*var_b[i] +
	       -2*var_c +
	        &lt;STRONG&gt;4*var_d&lt;/STRONG&gt;  ;
min obj=sum;
con con_total:sum&amp;gt;=1;
con con_a:sum{i in 1..2} var_a[i]=1;
con con_b:sum{i in 1..3} var_b[i]=1;
con con_d:&lt;STRONG&gt;var_c=2+4*var_d&lt;/STRONG&gt;;

solve ;

print a var_a ; 
print b var_b ;
print   var_c ;
&lt;STRONG&gt;print   var_d ;&lt;/STRONG&gt;
quit;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1739954638326.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104742i23D4A2BA1CEE2C0C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1739954638326.png" alt="Ksharp_0-1739954638326.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 08:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimize-Function-with-Opt-Model/m-p/959572#M4280</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-02-19T08:44:04Z</dc:date>
    </item>
  </channel>
</rss>

