/* Inputing values of multi-dimensional matrix incost in a table form first*/ Data incost; infile datalines dsd delimiter='09'x; input Product $ Plant $ DC $ incost; datalines; P1 Chicago Atlanta 6 P1 Chicago Boston 5 P1 Dallas Atlanta 4 P1 Dallas Boston 7 P1 Miami Atlanta 6 P1 Miami Boston 9 P2 Chicago Atlanta 6 P2 Chicago Boston 5 P2 Dallas Atlanta 4 P2 Dallas Boston 7 P2 Miami Atlanta 6 P2 Miami Boston 9 P3 Chicago Atlanta 6 P3 Chicago Boston 5 P3 Dallas Atlanta 4 P3 Dallas Boston 7 P3 Miami Atlanta 4 P3 Miami Boston 7 ; Run; /* Inputing values of multi-dimensional matrix outcost in a table form first*/ Data outcost; infile datalines dsd delimiter='09'x; input Product $ DC $ Region $ outcost; datalines; P1 Atlanta NY 8 P1 Atlanta VA 5 P1 Atlanta PA 6 P1 Boston NY 9 P1 Boston VA 7 P1 Boston PA 6 P2 Atlanta NY 7 P2 Atlanta VA 8 P2 Atlanta PA 5 P2 Boston NY 3 P2 Boston VA 8 P2 Boston PA 6 P3 Atlanta NY 7 P3 Atlanta VA 4 P3 Atlanta PA 4 P3 Boston NY 4 P3 Boston VA 5 P3 Boston PA 4 ; Run; proc optmodel; set Product = {'P1','P2','P3'}; set Plant = {'Chicago','Dallas','Miami'}; set DC = {'Atlanta','Boston'}; set Region = {'NY','VA','PA'}; number PlPrCapacity{Product,Plant} = [ 200 125 50 200 200 50 50 150 200]; number PlCapacity{Plant} = [2000 250 2000]; number DCCapacity{DC} = [200 500]; number incost{Product,Plant,DC}; Read data inCost into [Product Plant DC] inCost; number outcost{Product,DC,Region}; Read data outCost into [Product DC Region] outCost; number Demand{Product,Region} = [ 50 100 75 100 50 75 25 25 150]; var inflow{Product,Plant,DC} >= 0; var outflow{Product,DC,Region} >= 0; /* Minimize Total Transport cost = Inbound transport cost + Outbound transport cost */ minimize Z=sum{l in Product,i in Plant,k in DC}inflow[l,i,k]*incost[l,i,k]+ sum{l in Product, k in DC, j in Region}outflow[l,k,j]*outcost[l,k,j]; con PlantProdCon{l in Product,i in Plant}: sum{k in DC}inflow[l,i,k]<=PlPrCapacity[l,i]; con PlantCon{i in Plant}: sum{l in Product,k in DC}inflow[l,i,k]<=PlCapacity[i]; con DCCon{k in DC}: sum{l in Product,i in Plant}inflow[l,i,k]<=DCCapacity[k]; con DemandCon{l in Product,j in Region}: sum{k in DC}outflow[l,k,j]>=Demand[l,j]; con BalCon{l in Product,k in DC}: sum{i in Plant}inflow[l,i,k]=sum{j in Region}outflow[l,k,j]; solve; print z inflow outflow; quit;