BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

 

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

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

3 REPLIES 3
jhlaramore
SAS Employee

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

RobPratt
SAS Super FREQ

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-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

Register now!

Multiple Linear Regression in SAS

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.

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