<?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: Redistributing numbers in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963920#M4314</link>
    <description>&lt;P&gt;Hi RobPratt, I ran your whole code and it gives me the following table:&lt;/P&gt;
&lt;DIV id="tinyMceEditormlogan_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&lt;BR /&gt;
&lt;DIV class="lia-progress-placeholder mceNonEditable"&gt;
&lt;DIV class="lia-media-progress"&gt;&lt;I class="lia-fa lia-media-upload-progress lia-fa-picture-o"&gt;&lt;/I&gt;
&lt;DIV class="lia-progress-bar-stripes lia-progress-bar-animate lia-media-progress-bar"&gt;
&lt;DIV class="lia-progress-bar" style="width: 100%;"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;SPAN class="lia-progress-value"&gt;Updating Media&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Wed, 09 Apr 2025 18:18:13 GMT</pubDate>
    <dc:creator>mlogan</dc:creator>
    <dc:date>2025-04-09T18:18:13Z</dc:date>
    <item>
      <title>Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963804#M4302</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;I have the following dataset of the school where one course is offered at different classrooms. But in this case some classrooms are not full (ROOM_LOAD) for a given course. I wanted to redistribute the students in classrooms where there is still a capacity left and thus clear out a room and make it available for other use.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
    INPUT COURSE $ ROOM_NO $ ROOM_CAPACITY ROOM_LOAD;
    DATALINES;
CHEM101	C101	20	7
CHEM101	C102	20	11
CHEM101	C103	10	8
CHEM101	C104	15	10
BIO302	HB102	22	20
BIO302	HB106	24	12
BIO302	HB902	30	29
BIO302	W102	30	31
BIO302	AB102	40	27
;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;As a output, I want a table like this which will give me new student number (NEW_ROOM_LOAD) of each room after redistribution and also flag the room that come available (Room_Status). I have about 150 courses. That's why I need help with a dynamic code. Any help will be appreciated. I will really appreciate any help you can provide. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="596"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="63"&gt;COURSE&lt;/TD&gt;
&lt;TD width="73"&gt;ROOM_NO&lt;/TD&gt;
&lt;TD width="117"&gt;ROOM_CAPACITY&lt;/TD&gt;
&lt;TD width="88"&gt;ROOM_LOAD&lt;/TD&gt;
&lt;TD width="128"&gt;NEW_ROOM_LOAD&lt;/TD&gt;
&lt;TD width="127"&gt;Room_Status&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;CHEM101&lt;/TD&gt;
&lt;TD&gt;C101&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;TD&gt;17&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;CHEM101&lt;/TD&gt;
&lt;TD&gt;C102&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;TD&gt;11&lt;/TD&gt;
&lt;TD&gt;19&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;CHEM101&lt;/TD&gt;
&lt;TD&gt;C103&lt;/TD&gt;
&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;TD&gt;40&lt;/TD&gt;
&lt;TD&gt;27&lt;/TD&gt;
&lt;TD&gt;39&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 09 Apr 2025 01:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963804#M4302</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2025-04-09T01:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963810#M4304</link>
      <description>&lt;P&gt;It might be the case that more than one combination of rooms yield the minimum number needed.&amp;nbsp; But those combinations may have different total capacity for the unneeded rooms.&amp;nbsp; Do you want to maximize the total unallocated capacity among all the minimum-used-room combinations?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 03:01:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963810#M4304</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2025-04-09T03:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963817#M4305</link>
      <description>&lt;P&gt;Sorting the rooms by descending capacity helped to get the expected result.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= have;
    by course descending room_capacity;
run;

data want;
    num_students = 0;
    
    do _n_ = 1 by 1 until(last.course);
        set have;
        by course;
        
        num_students = num_students + room_load;
    end;
    
    do _n_ = 1 by 1 until(last.course);
        set have;
        by course;
        
        new_room_load = min(room_capacity, num_students);
        num_students = num_students - new_room_load;
        output;
    end;
        
    drop num_students;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Apr 2025 06:34:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963817#M4305</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2025-04-09T06:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963820#M4306</link>
      <description>&lt;P&gt;&lt;STRONG&gt;[Code has beed updated]&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;A very interesting question. I like it .&lt;/P&gt;
&lt;P&gt;But I think you need the help from SAS/OR module for solving such optimization issue.&lt;/P&gt;
&lt;P&gt;And calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;Here is an example I wrote:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
    INPUT COURSE $ ROOM_NO $ ROOM_CAPACITY ROOM_LOAD;
    DATALINES;
CHEM101	C101	20	7
CHEM101	C102	20	11
CHEM101	C103	10	8
CHEM101	C104	15	10
BIO302	HB102	22	20
BIO302	HB106	24	12
BIO302	HB902	30	29
BIO302	W102	30	31
BIO302	AB102	40	27
;
RUN;

%macro room(course=);
data temp;
set have;
if COURSE="&amp;amp;course.";
run;

proc optmodel;
set &amp;lt;str&amp;gt; ROOM_NO;
num ROOM_CAPACITY{ROOM_NO};
num ROOM_LOAD{ROOM_NO};
num sum_ROOM_LOAD=sum{i in ROOM_NO} ROOM_LOAD[i];
read data temp into ROOM_NO=[ROOM_NO] ROOM_CAPACITY ROOM_LOAD;
var v{ROOM_NO} binary;
min TotalCost =  (sum{i in ROOM_NO} ROOM_CAPACITY[i]*v[i]) - sum_ROOM_LOAD ;
con con: sum{i in ROOM_NO} ROOM_CAPACITY[i]*v[i] &amp;gt;= sum_ROOM_LOAD;
solve ;
create data want from [ROOM]={i in ROOM_NO} 
                      ROOM_CAPACITY=ROOM_CAPACITY[i] 
                      ROOM_LOAD=ROOM_LOAD[i] 
                     flag=v[i].sol;
quit;
data want;
length COURSE ROOM $ 80;
set want;
COURSE="&amp;amp;course.";
run;
proc append base=final_want data=want force;run;
%mend;

proc freq data=have noprint;
table course/out=course;
run;
proc delete data=final_want;run;
data _null_;
set course;
call execute(catt('%room(course=',course,')'));
run;


proc print data=final_want noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1744182154191.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106078i2819CE88F500CA7A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1744182154191.png" alt="Ksharp_0-1744182154191.png" /&gt;&lt;/span&gt;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 07:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963820#M4306</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-04-09T07:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963858#M4307</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;- what does the 'flag' variable indicate here?&amp;nbsp; Agree this is an interesting question.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 11:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963858#M4307</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-04-09T11:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963863#M4308</link>
      <description>&lt;P&gt;Here's an &lt;STRONG&gt;edited&lt;/STRONG&gt; version -- I changed the sort order based on what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;said above (sorting by room capacity - ascending in this case, though - instead of by # of vacancies) - now produces the same result, though not nearly as short as his:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have; by course room_capacity; run;

title 'before';
proc print data=have; run;

proc sql noprint;
select max(nrecs) into :maxrecs trimmed 
from 
	(select course, count(*) as nrecs from have group by course);
quit;

data want;
set have;
by course;
array T {&amp;amp;maxrecs, 2} _temporary_;
array C {&amp;amp;maxrecs} $8 _temporary_;
length cnum 3;
if first.course then call missing(of T[*], of C[*], cnum);
cnum+1;
C[cnum]=room_no;
T[cnum, 1]=room_capacity;
T[cnum, 2]=room_load;
if last.course then do;
	if cnum=1 then goto write;
	do i=1 to (cnum-1);
		do j=(i+1) to cnum;
			avail=T[j,1]-T[j,2];
			moved=min(T[i,2],avail);
			T[j,2]+moved;
			T[i,2]+(-moved);
			if T[i,2]=0 then leave;
		end;
	end;
	write:
	do i=1 to cnum;
		room_no=C[i];
		room_capacity=T[i,1];
		room_load=T[i,2];
		output;
	end;
end;
keep course room_:;
run;

title 'after';
proc print data=want; run;
title;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="quickbluefish_0-1744199452474.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106082iD60032559AB3723F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="quickbluefish_0-1744199452474.png" alt="quickbluefish_0-1744199452474.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>Wed, 09 Apr 2025 11:50:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963863#M4308</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-04-09T11:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963902#M4309</link>
      <description>Mank thanks Ksharp. Would it be possible for you to populate the column NEW_ROOM_LOAD	in the Final_want file so that I know how they were redistributed? I also wanted to ensure that room W102's number went down from 31 to 30. Thanks.</description>
      <pubDate>Wed, 09 Apr 2025 15:39:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963902#M4309</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2025-04-09T15:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963905#M4310</link>
      <description>.</description>
      <pubDate>Wed, 09 Apr 2025 15:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963905#M4310</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2025-04-09T15:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963916#M4311</link>
      <description>&lt;P&gt;Here's one way to solve the problem with PROC OPTMODEL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   /* declare parameters and read input data set */
   set &amp;lt;str,str&amp;gt; COURSE_ROOM;
   num capacity {COURSE_ROOM};
   num load {COURSE_ROOM};
   read data HAVE into COURSE_ROOM=[course room_no] capacity=room_capacity load=room_load;

   /* calculate demand per course */
   set &amp;lt;str&amp;gt; COURSES init {};
   num demand {COURSES} init 0;
   for {&amp;lt;c,r&amp;gt; in COURSE_ROOM} do;
      COURSES = COURSES union {c};
      demand[c] = demand[c] + load[c,r];
   end;

   /* declare decision variables */
   var NewRoomLoad {&amp;lt;c,r&amp;gt; in COURSE_ROOM} &amp;gt;= 0 &amp;lt;= capacity[c,r];
   var IsAvailable {COURSE_ROOM} binary;

   /* declare objective */
/*   max NumAvailable = sum {&amp;lt;c,r&amp;gt; in COURSE_ROOM} IsAvailable[c,r];*/
   max AvailableCapacity = sum {&amp;lt;c,r&amp;gt; in COURSE_ROOM} capacity[c,r] * IsAvailable[c,r];

   /* declare constraints */
   con RespectCapacity {&amp;lt;c,r&amp;gt; in COURSE_ROOM}:
      IsAvailable[c,r] = 1 implies NewRoomLoad[c,r] = 0;
/*   con RespectCapacity {&amp;lt;c,r&amp;gt; in COURSE_ROOM}:*/
/*      NewRoomLoad[c,r] &amp;lt;= NewRoomLoad[c,r].ub * (1 - IsAvailable[c,r]);*/
   con SatisfyDemand {c in COURSES}:
      sum {&amp;lt;(c),r&amp;gt; in COURSE_ROOM} NewRoomLoad[c,r] = demand[c];

   /* call MILP solver */
   solve;

   /* create output data set */
   create data WANT from [COURSE	ROOM_NO]={&amp;lt;c,r&amp;gt; in COURSE_ROOM}
      ROOM_CAPACITY=capacity ROOM_LOAD=load NEW_ROOM_LOAD=NewRoomLoad Room_Status=(if IsAvailable[c,r] &amp;gt; 0.5 then 'Available' else '');
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first MAX statement (commented out) maximizes the number of available rooms.&amp;nbsp; The second MAX statement maximizes the available capacity.&amp;nbsp; For your sample data, both objectives yield the same available rooms:&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;COURSE&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;ROOM_NO&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;ROOM_CAPACITY&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;ROOM_LOAD&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;NEW_ROOM_LOAD&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;Room_Status&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;CHEM101&lt;/TD&gt;
&lt;TD class="l data"&gt;C101&lt;/TD&gt;
&lt;TD class="r data"&gt;20&lt;/TD&gt;
&lt;TD class="r data"&gt;7&lt;/TD&gt;
&lt;TD class="r data"&gt;20&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;CHEM101&lt;/TD&gt;
&lt;TD class="l data"&gt;C102&lt;/TD&gt;
&lt;TD class="r data"&gt;20&lt;/TD&gt;
&lt;TD class="r data"&gt;11&lt;/TD&gt;
&lt;TD class="r data"&gt;16&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;CHEM101&lt;/TD&gt;
&lt;TD class="l data"&gt;C103&lt;/TD&gt;
&lt;TD class="r data"&gt;10&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="l data"&gt;Available&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;CHEM101&lt;/TD&gt;
&lt;TD class="l data"&gt;C104&lt;/TD&gt;
&lt;TD class="r data"&gt;15&lt;/TD&gt;
&lt;TD class="r data"&gt;10&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="l data"&gt;Available&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;BIO302&lt;/TD&gt;
&lt;TD class="l data"&gt;HB102&lt;/TD&gt;
&lt;TD class="r data"&gt;22&lt;/TD&gt;
&lt;TD class="r data"&gt;20&lt;/TD&gt;
&lt;TD class="r data"&gt;19&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;BIO302&lt;/TD&gt;
&lt;TD class="l data"&gt;HB106&lt;/TD&gt;
&lt;TD class="r data"&gt;24&lt;/TD&gt;
&lt;TD class="r data"&gt;12&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="l data"&gt;Available&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;BIO302&lt;/TD&gt;
&lt;TD class="l data"&gt;HB902&lt;/TD&gt;
&lt;TD class="r data"&gt;30&lt;/TD&gt;
&lt;TD class="r data"&gt;29&lt;/TD&gt;
&lt;TD class="r data"&gt;30&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;BIO302&lt;/TD&gt;
&lt;TD class="l data"&gt;W102&lt;/TD&gt;
&lt;TD class="r data"&gt;30&lt;/TD&gt;
&lt;TD class="r data"&gt;31&lt;/TD&gt;
&lt;TD class="r data"&gt;30&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;BIO302&lt;/TD&gt;
&lt;TD class="l data"&gt;AB102&lt;/TD&gt;
&lt;TD class="r data"&gt;40&lt;/TD&gt;
&lt;TD class="r data"&gt;27&lt;/TD&gt;
&lt;TD class="r data"&gt;40&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are using a SAS version that does not support indicator constraints (IMPLIES), you can use the second (commented out) RespectCapacity constraint instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might also be worth considering a secondary objective like minimizing the number of reassigned students.&amp;nbsp; Also, is there any concern about the reassignments introducing schedule conflicts where the same student is enrolled in different courses that meet at the same time?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 17:31:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963916#M4311</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2025-04-09T17:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963917#M4312</link>
      <description>Thank you RobPratt. It looks like we can move all students (12) from room HB106 and put them on AB102 and make room HB106 fully available. Also, I want the Room_Status flagged as AVAILABLE only when NEW_ROOM_LOAD=0. Would you please help a bit more.</description>
      <pubDate>Wed, 09 Apr 2025 17:56:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963917#M4312</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2025-04-09T17:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963918#M4313</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35631"&gt;@mlogan&lt;/a&gt;&amp;nbsp;Yes, my solution already does that.&amp;nbsp; HB106 has NEW_ROOM_LOAD = 0.&amp;nbsp; And Room_Status = 'Available'&amp;nbsp;if and only if NEW_ROOM_LOAD = 0.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 18:02:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963918#M4313</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2025-04-09T18:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963920#M4314</link>
      <description>&lt;P&gt;Hi RobPratt, I ran your whole code and it gives me the following table:&lt;/P&gt;
&lt;DIV id="tinyMceEditormlogan_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&lt;BR /&gt;
&lt;DIV class="lia-progress-placeholder mceNonEditable"&gt;
&lt;DIV class="lia-media-progress"&gt;&lt;I class="lia-fa lia-media-upload-progress lia-fa-picture-o"&gt;&lt;/I&gt;
&lt;DIV class="lia-progress-bar-stripes lia-progress-bar-animate lia-media-progress-bar"&gt;
&lt;DIV class="lia-progress-bar" style="width: 100%;"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;SPAN class="lia-progress-value"&gt;Updating Media&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 09 Apr 2025 18:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963920#M4314</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2025-04-09T18:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963922#M4315</link>
      <description>&lt;P&gt;Hi RobPratt, I ran your whole code and it gives me the following table:&lt;/P&gt;
&lt;DIV id="tinyMceEditormlogan_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 09 Apr 2025 18:20:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963922#M4315</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2025-04-09T18:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963923#M4316</link>
      <description>&lt;P&gt;Hi RobPratt, I ran your whole code and it gives me the following table. Should I get rid of any part of your code? Thanks.&lt;/P&gt;
&lt;DIV id="tinyMceEditormlogan_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;TABLE width="483"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="56"&gt;COURSE&lt;/TD&gt;
&lt;TD width="56"&gt;ROOM_NO&lt;/TD&gt;
&lt;TD width="98"&gt;ROOM_CAPACITY&lt;/TD&gt;
&lt;TD width="91"&gt;ROOM_LOAD&lt;/TD&gt;
&lt;TD width="98"&gt;NEW_ROOM_LOAD&lt;/TD&gt;
&lt;TD width="84"&gt;Room_Status&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;CHEM101&lt;/TD&gt;
&lt;TD&gt;C101&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;TD&gt;Available&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;CHEM101&lt;/TD&gt;
&lt;TD&gt;C102&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;TD&gt;11&lt;/TD&gt;
&lt;TD&gt;16&lt;/TD&gt;
&lt;TD&gt;Available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
&lt;TR&gt;
&lt;TD&gt;BIO302&lt;/TD&gt;
&lt;TD&gt;AB102&lt;/TD&gt;
&lt;TD&gt;40&lt;/TD&gt;
&lt;TD&gt;27&lt;/TD&gt;
&lt;TD&gt;13&lt;/TD&gt;
&lt;TD&gt;Available&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 09 Apr 2025 18:24:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963923#M4316</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2025-04-09T18:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963924#M4317</link>
      <description>&lt;P&gt;Did you get any error message in the log?&amp;nbsp; I suspect that your SAS version does not support indicator constraints (IMPLIES), in which case you should instead use the second (commented out) version of the RespectCapacity constraint.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 18:50:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963924#M4317</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2025-04-09T18:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963927#M4318</link>
      <description>&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It appears to me that your OPTMODEL code maximizes the total number of SEATS available in unused rooms.&amp;nbsp; Do I have that correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the OP appears to ask to maximize the number of unused ROOMS (minimize number of rooms used, actually).&amp;nbsp; Could there not be a configuration of room sizes that satisfy your objective but would not satisfy the OP's original request?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance, if there are six rooms with sizes 7, 6, 6, 5, 2, and 2.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&amp;nbsp; For total load 13, I believe&amp;nbsp;&lt;SPAN&gt;your code would select a 7 and 6, maximizing the number of seats in unused rooms (6+5+2+2=15).&amp;nbsp; And that result would also satisfy the objective of maximizing unassigned rooms.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;For total load 11, I think &lt;SPAN&gt;your code would use three rooms (7, and both 2's,) leaving 3 rooms (6+6+5=17) unused, maximizing seats in unused rooms.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;However, the minimum number of ROOMS needed for the total load would be two (7 and either 5 or 6), leaving 4 rooms free, but with smaller total capacity.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe the OP doesn't care about this issue.&amp;nbsp; But is there code that would do two levels of optimizing?First, minimize the count of used rooms.&amp;nbsp; Then, for all combinations satisfying that objective, find one that maximizes your objective - total seats in unused rooms.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 19:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963927#M4318</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2025-04-09T19:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963928#M4319</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;Yes, I included both objectives, with one of them commented out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, you can optimize multiple objectives sequentially, with a primary objective, secondary objective, tertiary objective, and so on.&amp;nbsp; Here is one such example:&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_061/ormpex/ormpex_ex19_toc.htm" target="_blank" rel="noopener"&gt;SAS Help Center: Distribution 1: Which Factories and Depots to Supply Which Customers&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 19:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963928#M4319</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2025-04-09T19:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963939#M4320</link>
      <description>Flag=1 stands for NOT Available.&lt;BR /&gt;Flag=0 stands for Available.</description>
      <pubDate>Thu, 10 Apr 2025 00:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963939#M4320</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-04-10T00:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Redistributing numbers</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963942#M4321</link>
      <description>&lt;P&gt;Sure. But that would lead to many combinations , here is one of combination:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA HAVE;
    INPUT COURSE $ ROOM_NO $ ROOM_CAPACITY ROOM_LOAD;
    DATALINES;
CHEM101	C101	20	7
CHEM101	C102	20	11
CHEM101	C103	10	8
CHEM101	C104	15	10
BIO302	HB102	22	20
BIO302	HB106	24	12
BIO302	HB902	30	29
BIO302	W102	30	31
BIO302	AB102	40	27
;
RUN;

%macro room(course=);
data temp;
set have;
if COURSE="&amp;amp;course.";
run;

proc optmodel;
set &amp;lt;str&amp;gt; ROOM_NO;
num ROOM_CAPACITY{ROOM_NO};
num ROOM_LOAD{ROOM_NO};
num sum_ROOM_LOAD=sum{i in ROOM_NO} ROOM_LOAD[i];
read data temp into ROOM_NO=[ROOM_NO] ROOM_CAPACITY ROOM_LOAD;
var v{ROOM_NO} binary;
min TotalCost =  (sum{i in ROOM_NO} ROOM_CAPACITY[i]*v[i]) - sum_ROOM_LOAD ;
con con: sum{i in ROOM_NO} ROOM_CAPACITY[i]*v[i] &amp;gt;= sum_ROOM_LOAD;
solve ;
create data want from [ROOM]={i in ROOM_NO} 
                      ROOM_CAPACITY=ROOM_CAPACITY[i] 
                      ROOM_LOAD=ROOM_LOAD[i] 
                     flag=v[i].sol;
quit;
data want;
length COURSE ROOM $ 80;
set want;
COURSE="&amp;amp;course.";
run;
proc append base=final_want data=want force;run;
%mend;

proc freq data=have noprint ;
table course/out=course;
run;
proc delete data=final_want;run;
data _null_;
set course;
call execute(catt('%room(course=',course,')'));
run;


&lt;STRONG&gt;

proc summary data=final_want ;
by course;
var room_load;
output out=sum(drop=_:) sum=sum;
run;
data final_want2;
 merge final_want sum;
 by course;
 if first.course then cum_ROOM_CAPACITY=0;
 new_room_load=0;
 if flag=1 then do; 
     cum_ROOM_CAPACITY+ROOM_CAPACITY;
     new_room_load=ifn(sum&amp;gt;=cum_ROOM_CAPACITY,ROOM_CAPACITY,ROOM_CAPACITY-cum_ROOM_CAPACITY+sum);
 end;
 drop sum cum_ROOM_CAPACITY;
run;&lt;/STRONG&gt;

&lt;STRONG&gt;proc print data=final_want2 noobs;run;&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1744248258855.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106103i36DD4C31E54A12AD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1744248258855.png" alt="Ksharp_0-1744248258855.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Apr 2025 01:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Redistributing-numbers/m-p/963942#M4321</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-04-10T01:24:25Z</dc:date>
    </item>
  </channel>
</rss>

