I'm trying to understand how to correctly structure the data in a SAS data set (or in an Excel file that can be converted into a SAS data set via PROC IMPORT) so the index sets and known parameters in the SET and NUM statements don't need to be hard coded within the OPTMODEL procedure.
My end goal is to create a generalizable optimization program that can accomodate any number of values based on a predefined SAS data set that can be read into OPTMODEL, so that if editing is required, all editing is done outside of the OPTMODEL procedure.
Below is a sample program. It executes and runs without error as is, but am having trouble with the issue mentioned above.
Thank you in advance for any help you can provide.
proc optmodel;
set DAYS=1..3;
set LAWNS=/Lawn1 Lawn2 Lawn3 Lawn4/;
num RevenueSchedule{DAYS,LAWNS}=[60 35 0 0 0 35 25 20 0 35 25 20];
num TimeAvailable{DAYS}=[8 6 6];
num TimePerLawn{LAWNS}=[6 4 3 3];
var Do{DAYS,LAWNS} >=0 binary;
impvar TimeSpentMowing{d in DAYS}= sum{l in LAWNS} Do[d,l]*TimePerLawn[l];
impvar TimeLeftOver{d in DAYS}= TimeAvailable[d] - TimeSpentMowing[d];
max TotalRevenue=sum{d in DAYS,l in LAWNS} Do[d,l]*RevenueSchedule[d,l];
con TimePerDay{d in DAYS}: TimeSpentMowing[d] <= TimeAvailable[d];
con NotMoreThanOnce{l in LAWNS}: sum{d in DAYS} Do[d,l]<=1;
solve;
print RevenueSchedule TimePerLawn;
print Do TimeAvailable TimeSpentMowing TimeLeftOver;
quit;
Here's one way, using three data sets:
data day_data;
input day TimeAvailable;
datalines;
1 8
2 6
3 6
;
data lawn_data;
input lawn $ TimePerLawn;
datalines;
Lawn1 6
Lawn2 4
Lawn3 3
Lawn4 3
;
data day_lawn_data;
input day lawn1-lawn4;
datalines;
1 60 35 0 0
2 0 35 25 20
3 0 35 25 20
;
proc optmodel;
set DAYS;
num TimeAvailable{DAYS};
read data day_data into DAYS=[day] TimeAvailable;
set <str> LAWNS;
num TimePerLawn{LAWNS};
read data lawn_data into LAWNS=[lawn] TimePerLawn;
num RevenueSchedule{DAYS,LAWNS};
read data day_lawn_data into [day] {j in LAWNS} <RevenueSchedule[day,j]=col(j)>;
You might also find this book of examples useful:
http://support.sas.com/documentation/cdl/en/ormpex/68157/HTML/default/viewer.htm#titlepage.htm
Attached is the program. The code above didn't come out as intented.
Here's one way, using three data sets:
data day_data;
input day TimeAvailable;
datalines;
1 8
2 6
3 6
;
data lawn_data;
input lawn $ TimePerLawn;
datalines;
Lawn1 6
Lawn2 4
Lawn3 3
Lawn4 3
;
data day_lawn_data;
input day lawn1-lawn4;
datalines;
1 60 35 0 0
2 0 35 25 20
3 0 35 25 20
;
proc optmodel;
set DAYS;
num TimeAvailable{DAYS};
read data day_data into DAYS=[day] TimeAvailable;
set <str> LAWNS;
num TimePerLawn{LAWNS};
read data lawn_data into LAWNS=[lawn] TimePerLawn;
num RevenueSchedule{DAYS,LAWNS};
read data day_lawn_data into [day] {j in LAWNS} <RevenueSchedule[day,j]=col(j)>;
You might also find this book of examples useful:
http://support.sas.com/documentation/cdl/en/ormpex/68157/HTML/default/viewer.htm#titlepage.htm
Thank you, Rob!
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.