A couple of suggestions:
1. You're calling the OPTMILP procedure, but the syntax more closely resembles the OPTMODEL procedure. Change PROC OPTMILP to PROC OPTMODEL
*proc optmilp;
proc optmodel;
2. Declare a set of ARCS indexed by both students and classes. Declare a payment parameter indexed by ARCS, and read the table into the OPTMODEL procedure.
set <num,str> ARCS;
num payment{ARCS};
read data work.input into ARCS = [student class] payment;
3. To create a set of STUDENTS and a set of CLASSES from the ARCS set, use the setof{ } operator.
set STUDENTS = setof{<s,c> in ARCS} s;
set CLASSES = setof{<s,c> in ARCS} c;
Full code below:
data work.input;
input student class $ payment;
datalines;
1 A 1
2 A 2
2 B 3
3 A 4
3 B 5
;
*proc optmilp;
proc optmodel;
set <num,str> ARCS;
num payment{ARCS};
read data work.input into ARCS = [student class] payment;
set STUDENTS = setof{<s,c> in ARCS} s;
set CLASSES = setof{<s,c> in ARCS} c;
/* write the elements of each set to the log */
put ARCS=;
put STUDENTS=;
put CLASSES=;
/* print payment to the results viewer */
print payment;
Structuring it this way allows you to sum across all students, or sum across all classes later in the program without the missing element <1,B> causing an issue:
num total_by_class{c in CLASSES} = sum{<s,(c)> in ARCS} payment[s,c];
num total_by_student{s in STUDENTS} = sum{<(s),c> in ARCS} payment[s,c];
print total_by_class;
print total_by_student;
The MISSINGS set below captures all of the student-class combinations not present in your data, and as a result, not part of the new calculated parameters above.
set MISSINGS = (STUDENTS cross CLASSES) diff ARCS;
put MISSINGS=;