Sorry for digging up this old thread, but this is exactly the issue i'm trying to solve, but i can't seem to get the code above to work. First, when i use var Assign >=0; I get an error on the objective function line as follows: min z = sum {<i,j> in POSSIBLE} cost[i,j]*Assign[i,j]; - 647 ERROR 647-782: The name 'Assign' must be an array. I can fix this error by using the following: var Assign{CASES,CONTROLS} >= 0; Is this reasonable? .. I am having a couple of additional problems. If I use this code, which I believe follows from reading all the posts in this thread, I end up with Case1 and Case3 both matching to Control3. Is there a way to prevent multiple cases matching to a single control? data cases_and_controls; length case $5; input case control1-control3; datalines; case1 . . 2 case2 1 5 . case3 . . 1 run; proc optmodel; /* define sets for cases and controls */ set <str> CASES; set <str> CONTROLS init (union{i in 1..3} {"control"||i}); /* define cost parameter */ num cost{CASES, CONTROLS}; /* read in data including missing values */ read data cases_and_controls into CASES=[case] {j in CONTROLS} < cost[case, j] = col(j) >; /* create a set of pairs which are possible, i.e. cost is not missing */ set <string, string> POSSIBLE = {i in CASES, j in CONTROLS: cost[i,j] > 0}; /* we only need variables for possible pairs */ var Assign{CASES,CONTROLS} >= 0; num maxCost = max{<i,j> in POSSIBLE} cost[i,j]; min z = sum {<i,j> in POSSIBLE} cost[i,j]*Assign[i,j] - sum {<i,j> in POSSIBLE} (maxCost+1)*Assign[i,j]; con case_assign{i in CASES}: sum{<(i),j> in POSSIBLE} Assign[i,j] <= 1; /* solve the model */ solve; /* print the result */ print Assign; create data assign from [i j] = {i in CASES, j in CONTROLS: Assign[i,j] >= 0.5} cost; quit;
... View more