<?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: Minimization challenge in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259198#M57431</link>
    <description>&lt;P&gt;thanks a lot Xia!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 26 Mar 2016 01:53:33 GMT</pubDate>
    <dc:creator>MetinBulus</dc:creator>
    <dc:date>2016-03-26T01:53:33Z</dc:date>
    <item>
      <title>Minimization challenge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259014#M57414</link>
      <description>&lt;P&gt;Hi everyone, I have a table similiar to this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;g &amp;nbsp; p1 &amp;nbsp; &amp;nbsp;p2 &amp;nbsp; &amp;nbsp;p3 &amp;nbsp; &amp;nbsp;p4 &amp;nbsp; &amp;nbsp;p5 &amp;nbsp; &amp;nbsp; &amp;nbsp;x&lt;/P&gt;
&lt;P&gt;0 &amp;nbsp; 0.80 &lt;STRONG&gt;0.86&lt;/STRONG&gt; 0.19 0.01 0.96 &amp;nbsp; 6&lt;/P&gt;
&lt;P&gt;0 &amp;nbsp; 0.15 0.57 &lt;STRONG&gt;0.87&lt;/STRONG&gt; 0.36 0.03 &amp;nbsp; 7&lt;/P&gt;
&lt;P&gt;0 &amp;nbsp; 0.41 &lt;STRONG&gt;0.75&lt;/STRONG&gt; 0.33 0.39 0.27 &amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;0 &amp;nbsp; 0.38 0.88 &lt;STRONG&gt;0.53&lt;/STRONG&gt; 0.49 0.17 &amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;0 &amp;nbsp; 0.14 0.32 0.09 0.35 &lt;STRONG&gt;0.63&lt;/STRONG&gt; &amp;nbsp; 9&lt;/P&gt;
&lt;P&gt;0 &amp;nbsp; 0.22 0.49 0.32 0.58 &lt;STRONG&gt;0.96 &amp;nbsp;&lt;/STRONG&gt; 2&lt;/P&gt;
&lt;P&gt;0 &amp;nbsp; 0.48&lt;STRONG&gt; 0.33&lt;/STRONG&gt; 0.98 0.19 0.42 &amp;nbsp; 8&lt;/P&gt;
&lt;P&gt;0 &amp;nbsp; &lt;STRONG&gt;0.30&lt;/STRONG&gt; 0.88 0.87 0.84 0.31 &amp;nbsp; 7&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; 0.32 0.31 &lt;STRONG&gt;0.10&lt;/STRONG&gt; 0.08 0.36 &amp;nbsp;10&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; 0.85 0.83 &lt;STRONG&gt;0.30&lt;/STRONG&gt; 0.40 0.97 &amp;nbsp; 8&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; 0.45 0.85 0.98 &lt;STRONG&gt;0.43&lt;/STRONG&gt; 0.16 &amp;nbsp; 7&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; 0.29 0.47 0.53 &lt;STRONG&gt;0.10&lt;/STRONG&gt; 0.13 &amp;nbsp;11&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; 0.84 &lt;STRONG&gt;0.58&lt;/STRONG&gt; 0.95 0.43 0.81 &amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; 0.28 0.18 &lt;STRONG&gt;0.06&lt;/STRONG&gt; 0.74 0.95 &amp;nbsp;24&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; 0.08 &lt;STRONG&gt;0.37&lt;/STRONG&gt; 0.97 0.17 0.88 &amp;nbsp; 9&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; 0.92 &lt;STRONG&gt;1.00&lt;/STRONG&gt; 0.47 0.27 0.82 &amp;nbsp; 4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each group I will have a weighted mean (1/&lt;EM&gt;&lt;STRONG&gt;pi&lt;/STRONG&gt;)&lt;/EM&gt;*&lt;EM&gt;x&lt;/EM&gt;/8.&amp;nbsp;I would like to minimize weighted mean difference between group 1 and 0,&amp;nbsp;&lt;SPAN&gt;by selecting one &lt;EM&gt;pi&lt;/EM&gt; from each row. &amp;nbsp;Any idea, help will appreciated.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Note:&amp;nbsp;Bold numbers are to show the idea and were not obtained using a minimization technique.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 05:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259014#M57414</guid>
      <dc:creator>MetinBulus</dc:creator>
      <dc:date>2016-03-25T05:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: Minimization challenge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259020#M57415</link>
      <description>&lt;PRE&gt;
How do you define a group's  weighted mean  (1/pi)*x/8 ?

For group 0 :
(1/0.86 )*x/8 + (1/0.87)*x/8 + (1/0.75)*x/8 +.....+(1/0.30)*x/8      ?

&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2016 07:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259020#M57415</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-25T07:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: Minimization challenge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259047#M57416</link>
      <description>&lt;PRE&gt;Xia, yes, I forgot to put a summation sign. 
weighted_mean_for_group_0 = (1/0.86 )*6/8 + (1/0.87)*7/8 + (1/0.75)*3/8 +.....+(1/0.30)*7/8 &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 11:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259047#M57416</guid>
      <dc:creator>MetinBulus</dc:creator>
      <dc:date>2016-03-25T11:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: Minimization challenge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259053#M57417</link>
      <description>&lt;PRE&gt;
OK. 
Here is my GA code, you can run it under SAS University Edition. Maybe someone could give you some SAS/OR code .
I really want to know how to do it by SAS/OR .
Good Luck.
The minimize difference is 0.0000176.

g   p1    p2    p3    p4    p5      x
0                 0.19                     6
0                           0.36           7
0                           0.39           3
0         0.88                             5
0                           0.35           9
0   0.22                                   2
0          0.33                           8
0                            0.84         7
1                                   0.36  10
1   0.85                                  8
1   0.45                                  7
1          0.47                          11
1                            0.43        5
1                                   0.95  24
1                                   0.88   9
1                  0.47                    4









data x;
input g   p1    p2    p3    p4    p5      x;
cards;
0   0.80 0.86 0.19 0.01 0.96   6
0   0.15 0.57 0.87 0.36 0.03   7
0   0.41 0.75 0.33 0.39 0.27   3
0   0.38 0.88 0.53 0.49 0.17   5
0   0.14 0.32 0.09 0.35 0.63   9
0   0.22 0.49 0.32 0.58 0.96   2
0   0.48 0.33 0.98 0.19 0.42   8
0   0.30 0.88 0.87 0.84 0.31   7
1   0.32 0.31 0.10 0.08 0.36  10
1   0.85 0.83 0.30 0.40 0.97   8
1   0.45 0.85 0.98 0.43 0.16   7
1   0.29 0.47 0.53 0.10 0.13  11
1   0.84 0.58 0.95 0.43 0.81   5
1   0.28 0.18 0.06 0.74 0.95  24
1   0.08 0.37 0.97 0.17 0.88   9
1   0.92 1.00 0.47 0.27 0.82   4
;
run;
data have;
 set x;
 length vname $ 40;
 array z{*} p1-p5 ;
 n+1;
 do i=1 to dim(z);
  vname=vname(z{i});v=z{i};output;
 end;
 drop i p1-p5;
run;


proc iml;
use have nobs nobs;
read all var {g n v x vname};
close have;

start_end=loc(n^=t({.}||remove(n,nobs))) //
              loc(n^=t(remove(n,1)||{.})) ;
              
mattrib start_end rowname={start end};                         
start function(z) global(v,x,g);
   idx0=z[loc(g[z]=0)] ;
   idx1=z[loc(g[z]=1)] ; 

   pi0=1/(8#v[idx0]); 
   pi1=1/(8#v[idx1]); 

   w_mean0=sum(pi0#x[idx0]);
   w_mean1=sum(pi1#x[idx1]);

   dif=abs(w_mean0-w_mean1); 
 return (dif);
finish;

encoding=start_end;
size=ncol(encoding);
id=gasetup(2,size,1234);
call gasetobj(id,0,"function");
call gasetsel(id,100,1,1);
call gainit(id,1000,encoding);
niter = 10000;
summary = j(niter,2);
do i = 1 to niter;
 call garegen(id);
 call gagetval(value, id);
 summary[i,1] = value[1];
 summary[i,2] = value[:];
end;
call gagetmem(mem, value, id, 1);
Memebers=x[mem];
obs=n[mem];
group=g[mem];
varname=vname[mem];
vv=v[mem];
print "Best Members:"  group obs varname vv[l="value"] Memebers[l="x"],
      "Min Difference:   " value[l = ""],
      (summary[niter-20:niter ,])[c = {"Min Difference"  "Avg Difference"} l="The last 20 iteration"]  ;
call gaend(id);
quit;









OUTPUT:

 	group	obs	varname	value	x
Best Members:	0	1	p3	0.19	6
 	0	2	p4	0.36	7
 	0	3	p4	0.39	3
 	0	4	p2	0.88	5
 	0	5	p4	0.35	9
 	0	6	p1	0.22	2
 	0	7	p2	0.33	8
 	0	8	p4	0.84	7
 	1	9	p5	0.36	10
 	1	10	p1	0.85	8
 	1	11	p1	0.45	7
 	1	12	p2	0.47	11
 	1	13	p4	0.43	5
 	1	14	p5	0.95	24
 	1	15	p5	0.88	9
 	1	16	p3	0.47	4
Min Difference:	0.0000176
The last 20 iteration
Min Difference	Avg Difference
0.0000176	0.1089383
0.0000176	0.1679158
0.0000176	0.126787
0.0000176	0.0798593
0.0000176	0.1253699
0.0000176	0.1260094
0.0000176	0.0681392
0.0000176	0.1495233
0.0000176	0.082787
0.0000176	0.1652973
0.0000176	0.1008417
0.0000176	0.1230794
0.0000176	0.078061
0.0000176	0.1358966
0.0000176	0.1289343
0.0000176	0.0961847
0.0000176	0.1474286
0.0000176	0.1196352
0.0000176	0.0874685
0.0000176	0.1541393
0.0000176	0.1372184


&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2016 12:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259053#M57417</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-25T12:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: Minimization challenge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259067#M57418</link>
      <description>&lt;P&gt;The optimal objective value is smaller:&amp;nbsp;&lt;/P&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: PrintTable" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;
&lt;P&gt;6.9765E-07&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can solve this by using PROC OPTMODEL in&amp;nbsp;SAS/OR as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n = 5;

data x;
   input g p1-p&amp;amp;n x;
   cards;
0   0.80 0.86 0.19 0.01 0.96   6
0   0.15 0.57 0.87 0.36 0.03   7
0   0.41 0.75 0.33 0.39 0.27   3
0   0.38 0.88 0.53 0.49 0.17   5
0   0.14 0.32 0.09 0.35 0.63   9
0   0.22 0.49 0.32 0.58 0.96   2
0   0.48 0.33 0.98 0.19 0.42   8
0   0.30 0.88 0.87 0.84 0.31   7
1   0.32 0.31 0.10 0.08 0.36  10
1   0.85 0.83 0.30 0.40 0.97   8
1   0.45 0.85 0.98 0.43 0.16   7
1   0.29 0.47 0.53 0.10 0.13  11
1   0.84 0.58 0.95 0.43 0.81   5
1   0.28 0.18 0.06 0.74 0.95  24
1   0.08 0.37 0.97 0.17 0.88   9
1   0.92 1.00 0.47 0.27 0.82   4
;

proc optmodel;
   set OBS;
   set GROUPS = 0..1;
   set NSET = 1..&amp;amp;n;
   num group {OBS};
   num p {OBS, NSET};
   num x {OBS};
   read data x into OBS=[_N_] group=g {n in NSET} &amp;lt;p[_N_,n]=col('p'||n)&amp;gt; x;
   set OBS_g {g in GROUPS} = {i in OBS: group[i] = g};

   var Assign {OBS, NSET} binary;
   con AssignCon {i in OBS}:
      sum {n in NSET} Assign[i,n] = 1;
   impvar Mean {g in GROUPS} 
      = sum {i in OBS_g[g], n in NSET} (x[i]/p[i,n]) * Assign[i,n] / card(OBS_g[g]);
   var Surplus &amp;gt;= 0, Slack &amp;gt;= 0;
   min AbsDiff = Surplus + Slack;
   con AbsDiffCon:
      Mean[0] - Mean[1] = Surplus - Slack;

   solve with MILP / inttol=1e-9;
   print {i in OBS, n in NSET: Assign[i,n].sol &amp;gt; 0.5} p;
   for {i in OBS, n in NSET} fix Assign[i,n] = round(Assign[i,n]);
   print Mean (abs(Mean[0]-Mean[1]));
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The resulting output is:&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: PrintTable" 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="l b header" scope="col"&gt;[2]&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;p&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;0.86&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;0.03&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;0.27&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;0.53&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;0.09&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;0.32&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;7&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;0.42&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;8&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;0.88&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;9&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;0.32&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;10&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;0.30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;11&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;0.16&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;12&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;0.13&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;13&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;0.95&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;14&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;0.28&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;15&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;0.08&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;16&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;0.92&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: PrintTable" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt; &lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&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;Mean&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;49.263&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;49.263&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: PrintTable" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;6.9765E-07&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 25 Mar 2016 14:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259067#M57418</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2016-03-25T14:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Minimization challenge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259198#M57431</link>
      <description>&lt;P&gt;thanks a lot Xia!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2016 01:53:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259198#M57431</guid>
      <dc:creator>MetinBulus</dc:creator>
      <dc:date>2016-03-26T01:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: Minimization challenge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259199#M57432</link>
      <description>&lt;P&gt;thanks a lot Rob! I will try both algorithms on some simulated data, and see if I can decode the algorithms logic also.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2016 01:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/259199#M57432</guid>
      <dc:creator>MetinBulus</dc:creator>
      <dc:date>2016-03-26T01:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: Minimization challenge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/261732#M57632</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24060"&gt;@MetinBulus﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks for posting this interesting challenge recently.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two advanced solutions have been provided, using genetic algorithms (SAS/IML) and mixed integer linear programming (SAS/OR), respectively.&amp;nbsp;I'm not familiar with either of these techniques and I don't have a license for those SAS modules.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to add a third solution using only Base SAS. It's a brute force approach. So, it may not scale well to a much larger input dataset (unlike the other two solutions, I assume, because neither &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;&amp;nbsp;nor &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt﻿&lt;/a&gt;&amp;nbsp;asked about the size of the real dataset).&amp;nbsp;With the sample data from your initial post it takes less than one second (on my workstation) to obtain five solutions with the same optimal (minimum) difference, which turns out to be &lt;STRONG&gt;exactly zero&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I have verified that in all five cases these zero differences are not just due to rounding (of weighted means with unit 1E-13, which I did in order to counter rounding errors in the calculation). Of course, this assumes that the values p1, ..., p5 and x of the input dataset are exact.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Read test data */

data have;
input g p1-p5 x;
cards;
0   0.80 0.86 0.19 0.01 0.96   6
0   0.15 0.57 0.87 0.36 0.03   7
0   0.41 0.75 0.33 0.39 0.27   3
0   0.38 0.88 0.53 0.49 0.17   5
0   0.14 0.32 0.09 0.35 0.63   9
0   0.22 0.49 0.32 0.58 0.96   2
0   0.48 0.33 0.98 0.19 0.42   8
0   0.30 0.88 0.87 0.84 0.31   7
1   0.32 0.31 0.10 0.08 0.36  10
1   0.85 0.83 0.30 0.40 0.97   8
1   0.45 0.85 0.98 0.43 0.16   7
1   0.29 0.47 0.53 0.10 0.13  11
1   0.84 0.58 0.95 0.43 0.81   5
1   0.28 0.18 0.06 0.74 0.95  24
1   0.08 0.37 0.97 0.17 0.88   9
1   0.92 1.00 0.47 0.27 0.82   4
;

/* Determine group sizes */

proc sql noprint;
select count(*) into :n0-:n1
from have
group by g;
quit;

%let rdunit=1E-13; /* rounding unit for weighted means (data dependent, though) */

/* Calculate "weighted means" in group 0 and group 1 */

%macro calc(g=, nrows=, ncols=5);
  %local i;
  data wm&amp;amp;g;
  set have end=last;
  where g=&amp;amp;g;
  array p p:;
  array a[&amp;amp;nrows, &amp;amp;ncols] _temporary_;
  array k[&amp;amp;nrows];
  do j=1 to &amp;amp;ncols;
    a[_n_,j]=x/p[j]; 
  end;
  if last then do;
  %do i=1 %to &amp;amp;nrows;
    do k&amp;amp;i=1 to &amp;amp;ncols;
  %end;
      m=0;
      do i=1 to &amp;amp;nrows;
        m+a[i, k[i]];
      end;
      m=round(m/&amp;amp;nrows, &amp;amp;rdunit); 
      output;
  %do i=1 %to &amp;amp;nrows;
    end;
  %end;
  end;
  keep g k: m;
  run;

  proc sort data=wm&amp;amp;g;
  by m;
  run;
%mend calc;
%calc(g=0, nrows=&amp;amp;n0);
%calc(g=1, nrows=&amp;amp;n1);

/* Bring weighted means of similar size together */

data wm;
set wm0
    wm1;
by m;
run;

/* Compute between-group differences of weighted means and determine
   the minimum difference (taking rounding issues into consideration) */

data diff;
retain min_d;
set wm end=last;
by g notsorted;
if last.g | first.g &amp;amp; _n_&amp;gt;1;
d=dif(m);
if ~first.g then d=.;
if d&amp;gt;. then min_d=min(min_d, d);
if last then call symputx('smalldiff', min_d+&amp;amp;rdunit);
drop min_d;
run;

/* Select pairs of obs. with (approx.) minimum difference
   (If there were clusters of more than two observations, this code 
    could be amended to select all pairs from these clusters.) */
    
data sel;
set diff end=last;
c+1;
if .&amp;lt;d&amp;lt;=&amp;amp;smalldiff then do;
  s+1;
  do i=c-1 to c;
    set diff point=i;
    if i&amp;lt;c then d=.;
    output;
  end;
end;
if last then call symputx('s',s);
label g='Group'
      s='Solution no.'
      m='Weighted mean'
      d='Difference';
drop c;
run;

proc sort data=sel;
by s g;
run;

/* Prepare and create output dataset WANT */

data haves;
set have;
do s=1 to &amp;amp;s;
  output;
end;
proc sort;
by s;
run;

data want;
merge haves
      sel;
by s g;
array a p:;
array k k:;
if first.g then j=0;
j+1;
i=k[j];
p=a[i];
keep s g i p x;
label i='Column';
run;

/* Show results */

* options formdlim=' ' nodate nonumber;
* title;

proc print data=want label noobs;
by s;
var g i p x;
run;

proc print data=sel width=min label noobs;
format m d 17.13;
run;
* options formdlim='';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 14:23:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/261732#M57632</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-06T14:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: Minimization challenge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/261879#M57648</link>
      <description>&lt;P&gt;Nice job, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;. &amp;nbsp;Yes, the MILP approach should scale better than brute force. &amp;nbsp;You can use the MILP solver's ABSOBJGAP= option to avoid terminating early with a solution that is "only" within 1e-6 of optimal. &amp;nbsp;Here's another near miss:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: PrintTable" 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="l b header" scope="col"&gt;[2]&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;p&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;0.19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;0.03&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;0.27&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;0.38&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;0.63&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;0.22&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;7&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;0.42&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;8&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;0.30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;9&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;0.10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;10&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;0.97&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;11&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;0.16&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;12&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;0.29&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;13&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;0.95&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;14&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;0.74&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;15&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;0.08&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;16&lt;/TH&gt;
&lt;TH class="l rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;0.27&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;BR /&gt;&lt;A target="_blank" name="IDX66"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: PrintTable" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt; &lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&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;Mean&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;44.367&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;44.367&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;BR /&gt;&lt;A target="_blank" name="IDX67"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: PrintTable" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2.6602E-10&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24060"&gt;@MetinBulus﻿&lt;/a&gt;, what is the original motivation for this problem?&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 06 Apr 2016 18:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Minimization-challenge/m-p/261879#M57648</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2016-04-06T18:15:33Z</dc:date>
    </item>
  </channel>
</rss>

