Hi Everyone,
I have some questions about data set definition in an optimization model.
One of the constraints is: sum {i in DivBlocks
But I do not know how to create the data set of MaxDivPrntArea, can you tell me how to create it?
PS: the length of MaxDivPrntArea
Thank you very much for your help!
The index set for MaxDivPrntArea should match (or be a subset of) the index set for your constraint. More explicitly, suppose you have a SAS data set called mydata that contains k and MaxDivPrntArea. Then you need something like this:
set KSET;
num MaxDivPrntArea {KSET};
read data mydata into KSET=
con Mycon {k in KSET}:
sum {i in DivBlocks
Or are you having trouble creating the mydata SAS data set itself?
In any case, you might find it useful to read some of the examples here:
SAS/OR(R) 13.2 User's Guide: Mathematical Programming Examples
Hi RobPratt,
Thank you for your answers! I am not sure how to create DivBlocks either.
I want to create a set DivBlocks which has 2 levels indices: 1. index k for the first level; 2. given a particular level, DivBlocks
Because the length of the first level of DivBlocks may change for different applications, I think it would be better not to list them one by one. Could you help me to get the answers? Thank you for your kind help!
First create a SAS data set as follows:
data indata;
input k i;
datalines;
1 1
1 2
1 5
2 3
2 7
3 4
3 6
3 8
3 9
;
In PROC OPTMODEL, you can read these pairs like this:
set <num,num> KI;
read data indata into KI=[k i];
One approach to express the desired constraint is to use an implicit slice:
set KSET = setof {<k,i> in KI} k;
con Mycon {k in KSET}:
sum {<(k),i> in KI, j in Pages} BlockSize * BlockAssign[i,j] <= MaxDivPrntArea
If you insist on using DivBlocks, here is an alternative approach that uses the SETOF operator again:
set DivBlocks {k in KSET} = setof {<(k),i> in KI} i;
con Mycon {k in KSET}:
sum {i in DivBlocks
A third approach passes through the KI set only once to construct both KSET and DivBlocks:
set KSET init {};
set DivBlocks {KSET} init {};
for {<k,i> in KI} do;
KSET = KSET union {k};
DivBlocks
end;
con Mycon {k in KSET}:
sum {i in DivBlocks
The doc link referenced in my previous reply contains numerous relevant examples. Search for "sets indexed by other sets" in the pdf.
Hi RobPatt,
Thank you a lot for your help!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.