Sure. But that would lead to many combinations , here is one of combination:
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="&course.";
run;
proc optmodel;
set <str> 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] >= 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="&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 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>=cum_ROOM_CAPACITY,ROOM_CAPACITY,ROOM_CAPACITY-cum_ROOM_CAPACITY+sum);
end;
drop sum cum_ROOM_CAPACITY;
run;
proc print data=final_want2 noobs;run;
... View more