<?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: Problem in formulating constraint in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/424753#M2171</link>
    <description>&lt;P&gt;Here's a way to do it with the CLP solver in PROC OPTMODEL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   num n = 5;
   var x {1..n} binary;
   con ChooseThree:
      sum {j in 1..n} x[j] = 3;
   /* exclude (...,1,...,0,...,1,...) */
   con Consecutive {j1 in 1..n-2, j2 in j1+1..n-1, j3 in j2+1..n}:
      x[j1] + (1 - x[j2]) + x[j3] &amp;lt;= 2;

   solve with clp / findallsolns;
   print {s in 1.._NSOL_, j in 1..n} x[j].sol[s];
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS Output&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: x.SOL" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="c b header" colspan="6" scope="colgroup"&gt;x.SOL&lt;/TH&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="c headerempty" scope="col"&gt;&amp;nbsp;&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;1&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;2&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;3&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;4&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;5&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;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&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;0&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;0&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;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Wed, 03 Jan 2018 23:02:05 GMT</pubDate>
    <dc:creator>RobPratt</dc:creator>
    <dc:date>2018-01-03T23:02:05Z</dc:date>
    <item>
      <title>Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140926#M736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I have a &lt;STRONG&gt;binary&lt;/STRONG&gt; variable x(b) where b ranges from 1 to 5.&lt;/P&gt;&lt;P&gt;Now I have a constraint which says that summation of x(b) over all b is either 0 or 3.&lt;/P&gt;&lt;P&gt;However all the x(b)'s with value 1 need to be together.&lt;/P&gt;&lt;P&gt;For example I can have the following sequences:&lt;/P&gt;&lt;P&gt;0 0 0 0 0&lt;/P&gt;&lt;P&gt;0 0 1 1 1&lt;/P&gt;&lt;P&gt;0 1 1 1 0&lt;/P&gt;&lt;P&gt;1 1 1 0 0&lt;/P&gt;&lt;P&gt;However I cannot have the following sequences.&lt;/P&gt;&lt;P&gt;1 0 1 0 1&lt;/P&gt;&lt;P&gt;0 1 1 0 1&lt;BR /&gt;Any help in formulating this constraint will be greatly appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 12:00:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140926#M736</guid>
      <dc:creator>abhik_giri</dc:creator>
      <dc:date>2014-03-12T12:00:41Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140927#M737</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure if this is what you want, but it seems to me more of a data manipulation question:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input b1-b5;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;0 0 0 0 0&lt;/P&gt;&lt;P&gt;0 0 1 1 1&lt;/P&gt;&lt;P&gt;0 1 1 1 0&lt;/P&gt;&lt;P&gt;1 1 1 0 0&lt;/P&gt;&lt;P&gt;1 0 1 0 1&lt;/P&gt;&lt;P&gt;0 1 1 0 1&lt;/P&gt;&lt;P&gt;0 1 1 1 1&lt;/P&gt;&lt;P&gt;0 0 1 1 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array b b:;&lt;/P&gt;&lt;P&gt; if (find(cats(of b(*)),'111') &amp;gt;0 and sum(of b(*)) =3) or sum(of b(*))=0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 13:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140927#M737</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-03-12T13:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140928#M738</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply Haikuo. Sorry if I didn't make my question more clear previously: x(b) is the desired output (of the optimization model), it's not the input.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 13:47:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140928#M738</guid>
      <dc:creator>abhik_giri</dc:creator>
      <dc:date>2014-03-12T13:47:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140929#M739</link>
      <description>&lt;P&gt;Here's a way to do it by using PROC OPTMODEL in SAS/OR:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc optmodel;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; num n = 5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; var x {1..n} binary;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; var y binary;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; con ZeroOrThree:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum {j in 1..n} x[j] = 3*y;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; /* exclude (1,...,0,...,1) */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; con Consecutive {j1 in 1..n-2, j2 in j1+1..n-1, j3 in j2+1..n}:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x[j1] + (1 - x[j2]) + x[j3] &amp;lt;= 2;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 21:17:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140929#M739</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2018-01-03T21:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140930#M740</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Rob, this looks to be a great solution when there is only &lt;STRONG&gt;one &lt;/STRONG&gt;'0' in the middle with '1's on both sides of it. However I forgot to mention another possible case which needs to be excluded (by using the constraint). In this case, there are &lt;STRONG&gt;multiple&lt;/STRONG&gt; '0's in the middle with '1's on both sides of it. Example: 1 0 0 1 1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Mar 2014 09:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140930#M740</guid>
      <dc:creator>abhik_giri</dc:creator>
      <dc:date>2014-03-13T09:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140931#M741</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For each triple (j1,j2,j3) where j1 &amp;lt; j2 &amp;lt; j3, the constraints I suggested exclude x[j1] = 1, x[j2] = 0, x[j3] = 1, even if j1, j2, and j3 are not consecutive.&amp;nbsp; Your example 1 0 0 1 1 is excluded by the constraint indexed by (j1,j2,j3) = (1,2,4).&amp;nbsp; (It is also excluded by a few other triples.)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Mar 2014 15:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140931#M741</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2014-03-13T15:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140932#M742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a constraint of the following form:&lt;/P&gt;&lt;P&gt;x(i)/A-x(i')/B+slack(i,i')-surplus(i,i')=0 for all i,i' such that i=1 to 99, i=2 to 100 and i&amp;lt;i'&lt;/P&gt;&lt;P&gt;However, the set to which i and i' belong is a string, not a number so I can't write "i in 1..100".&lt;/P&gt;&lt;P&gt;Will DO loop be better for this? If yes, can you help me with the syntax?&lt;/P&gt;&lt;P&gt;I couldn't find syntax for "Constraint DO loop" in Google.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Apr 2015 18:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140932#M742</guid>
      <dc:creator>abhik_giri</dc:creator>
      <dc:date>2015-04-17T18:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140933#M743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The simplest solution, if you will manipulate the strings as numbers, and you can be sure that they will always be numbers, is to create a set of numbers mapped to the set of strings, like this example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: small;"&gt;proc optmodel;&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: small;"&gt;&amp;nbsp;&amp;nbsp; set S = / '1' '2' '3' /;&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: small;"&gt;&amp;nbsp;&amp;nbsp; set SNUM = setof{si in S} input(si,best12.);&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: small;"&gt;&amp;nbsp;&amp;nbsp; num n{si in SNUM} = si;&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: small;"&gt;&amp;nbsp;&amp;nbsp; put n&lt;LI&gt;=;&lt;/LI&gt;&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: small;"&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Apr 2015 18:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140933#M743</guid>
      <dc:creator>LeoLopes</dc:creator>
      <dc:date>2015-04-17T18:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140934#M744</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot. But how do I code the constraint:&lt;/P&gt;&lt;P&gt;x(i)/A-x(i')/B+slack(i,i')-surplus(i,i')=0 for all i,i' such that i=1 to 99, i=2 to 100 and i&amp;lt;i'&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Apr 2015 18:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140934#M744</guid>
      <dc:creator>abhik_giri</dc:creator>
      <dc:date>2015-04-17T18:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140935#M745</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The simplest way to index them might be to define this set:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;num n ; /* you will initialize n from data */&lt;/P&gt;&lt;P&gt;set PAIRS = {i in 1 .. n,j in i + 1 .. n};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then index your variables and constraints on PAIRS, e.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;con ScaledDifference{&amp;lt;i,iPrime&amp;gt; in PAIRS}: X&lt;I&gt;/A + Slack[i,iPrime] - Surplus[i,iPrime] = X[iPrime]/B; &lt;/I&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Apr 2015 18:36:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140935#M745</guid>
      <dc:creator>LeoLopes</dc:creator>
      <dc:date>2015-04-17T18:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140936#M746</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Alternatively, you can keep the string indices if you define PAIRS as:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; PAIRS = {i in ISET, iprime in ISET: i &amp;lt; iprime};&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;where ISET is the common, string-valued index set for i and iprime.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Apr 2015 19:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140936#M746</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2015-04-17T19:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140937#M747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;data _null_;
array x[5];
n=dim(x);
k=-1;
nsubs=2**n;
do i=1 to nsubs;
rc=graycode(k,of x&lt;LI&gt;);
if prxmatch('/^0*1{2,}0*$|^0+$/',cats(of x&lt;/LI&gt;&lt;LI&gt;)) and sum(of x&lt;/LI&gt;&lt;LI&gt;) in (0 3) then
put&amp;nbsp; x&lt;/LI&gt;&lt;LI&gt; ;
end;
run;

&lt;/LI&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 18 Apr 2015 07:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/140937#M747</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-04-18T07:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/424544#M2169</link>
      <description>&lt;P&gt;Remember Permutation/Combination Chapter from +2 days ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;If {for i = 1 to 5} sum x(i) = 3 and x(i)'s are binary then there will be three 1's and two 0's.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me reframe the problem in the following way -&amp;nbsp;&lt;/P&gt;&lt;P&gt;In how many ways three&amp;nbsp;1's and two 0's can be arranged in permutation so that 1's always come together ? We consider three 1's as a single unit(let's say =3) and proceed with the permutation. So it would be 3! total. [For the time being, lets forget as two 0's are actually the same, so total number of permutation would be 3!/2!. Actually I could not find out this option in SAS. Please update me if anybody gets it]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc plan;
factors Block=6 ordered B=3 of 3 perm;
ods output Plan=results;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;This will produce the following output-&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Block B1 B2 B3
1 1 2 3
2 1 3 2
3 2 1 3
4 2 3 1
5 3 1 2
6 3 2 1&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Once you replace the value of B1/B2/B3 as follows you will find few&amp;nbsp;duplication in blocks.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data results(keep=Digit);
set results;
format Digit1 Digit2 Digit3 $5.;
if B1 in (1,2) then Digit1='0'; else Digit1 = '1-1-1';
if B2 in (1,2) then Digit2='0'; else Digit2 = '1-1-1';
if B3 in (1,2) then Digit3='0'; else Digit3 = '1-1-1';
Digit = CATX ("-", OF  Digit1-Digit3);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Results -&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Digit
0-0-1-1-1
0-1-1-1-0
0-0-1-1-1
0-1-1-1-0
1-1-1-0-0
1-1-1-0-0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Dedupe it -&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=results nodupkey; by Digit; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And you get the desired results-&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Digit
0-0-1-1-1
0-1-1-1-0
1-1-1-0-0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Use substr function to create 5 column from the Digit column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 11:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/424544#M2169</guid>
      <dc:creator>baralamit0</dc:creator>
      <dc:date>2018-01-03T11:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/424753#M2171</link>
      <description>&lt;P&gt;Here's a way to do it with the CLP solver in PROC OPTMODEL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   num n = 5;
   var x {1..n} binary;
   con ChooseThree:
      sum {j in 1..n} x[j] = 3;
   /* exclude (...,1,...,0,...,1,...) */
   con Consecutive {j1 in 1..n-2, j2 in j1+1..n-1, j3 in j2+1..n}:
      x[j1] + (1 - x[j2]) + x[j3] &amp;lt;= 2;

   solve with clp / findallsolns;
   print {s in 1.._NSOL_, j in 1..n} x[j].sol[s];
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS Output&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: x.SOL" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="c b header" colspan="6" scope="colgroup"&gt;x.SOL&lt;/TH&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="c headerempty" scope="col"&gt;&amp;nbsp;&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;1&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;2&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;3&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;4&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;5&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;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&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;0&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;0&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;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 03 Jan 2018 23:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/424753#M2171</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2018-01-03T23:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/424778#M2174</link>
      <description>&lt;P&gt;I've attached&amp;nbsp;PROC OPTMODEL code&amp;nbsp;that uses the REIFY and GCC constraints with the CLP solver.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 22:57:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/424778#M2174</guid>
      <dc:creator>lipury</dc:creator>
      <dc:date>2018-01-03T22:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in formulating constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/425424#M2176</link>
      <description>&lt;P&gt;PROC OPTMODEL comes with SAS-OR License. Which is bit costly and sometimes is not available.&lt;/P&gt;&lt;P&gt;Whereas Proc PLAN comes with the BASE SAS only.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 22:28:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Problem-in-formulating-constraint/m-p/425424#M2176</guid>
      <dc:creator>baralamit0</dc:creator>
      <dc:date>2018-01-05T22:28:22Z</dc:date>
    </item>
  </channel>
</rss>

