Hi, I haven't used SAS in some time and so I'm somewhat rusty, and my organization will start using SAS OR soon. To prepare I've devised a practice problem for myself.
I'm optimizing a simple employee schedule and have the following constraint where each shift length must be at least 3 hours.
Assigned shifts are represented using a two dimensional array as shown below.
employee 8-9 9-10 10-11 etc
jack 0 1 1
mark 0 0 0
jane 1 1 1
etc
1 means that employee is assigned to that time and 0 means they are not. The array is declared with sets (I will read in the contents of the sets, so the size is variable). Below is the declaration.
set <string> employees;
set <string> shifts;
num assignedShifts{employees, shifts}
Below is the code for the constraint.
dcl num index;
dcl num sum;
constraint shiftLength{e in employees, s in shifts}:
*need to introduce logic to separate morning/afeternoon shift requirements;
if assignedShifts{e, s} = 1 then do;
*does this assignment statement work?;
index = s;
sum = 0;
*need to somehow get set size to check bounderies;
do while(assignedShifts{e, index});
sum = sum + assignedShifts{e, index};
index = index + 1;
end;
s = index;
end;
sum >= 3;
The logic I have devised for checking if each shift is three hours or not is to sum each consecutive assignment value until I run into a 0.
Question 1: I declare a numerical index, assign the value of s to it, increment the index variable, then re-assigned the it's value to s. Is this valid? If not then how would I accomplish this?
Question 2: The code I have will throw an "index out of bounds" error because I don't check that index is within the number of shifts. The number of shifts is variable since I read in the set. How do I check the size of the set at run time?
Question 3: Say I have another shift length constraint that only checks shifts in the afternoon. How would I set s to "start" at an nth value in set shifts (or to stop at an nth)?
Thanks for your help!