Operations Research topics: SAS/OR,
SAS Optimization, and SAS Simulation Studio

How to Correctly Structure and Read a SAS data set into OPTMODEL

Accepted Solution Solved
Reply
SAS Employee
Posts: 15
Accepted Solution

How to Correctly Structure and Read a SAS data set into OPTMODEL

 

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;

 

 


Accepted Solutions
Solution
‎04-08-2016 05:45 PM
SAS Employee
Posts: 448

Re: How to Correctly Structure and Read a SAS data set into OPTMODEL

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

View solution in original post


All Replies
SAS Employee
Posts: 15

Re: How to Correctly Structure and Read a SAS data set into OPTMODEL

Attached is the program. The code above didn't come out as intented. 

Attachment
Solution
‎04-08-2016 05:45 PM
SAS Employee
Posts: 448

Re: How to Correctly Structure and Read a SAS data set into OPTMODEL

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

SAS Employee
Posts: 15

Re: How to Correctly Structure and Read a SAS data set into OPTMODEL

Thank you, Rob! 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 262 views
  • 0 likes
  • 2 in conversation