BookmarkSubscribeRSS Feed
Ibraheem123
Calcite | Level 5

I don't know where  is the problem  ?

this is my code 

/* 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 Barranqu Bogotá 130
P1 Barranqu Medellín 90.6
P1 Barranqu Cali 142
P1 Santander Bogotá 53.6
P1 Santander Medellín 41.6
P1 Santander Cali 88.8
P2 Barranqu Bogotá 130
P2 Barranqu Medellín 90.6
P2 Barranqu Cali 142
P2 Santander Bogotá 53.6
P2 Santander Medellín 41.6
P2 Santander Cali 88.8

;
Run;


proc optmodel;

set Product = {'P1','P2'};
set Plant = {'Barranqu','Santander'};
set DC = {'Bogotá','Medellín','Cali'};

 

number PlCapacity{Plant} = [610 350 ];

number incost{Product,Plant,DC};
Read data inCost into [Product Plant DC] inCost;


number Demand{Product,DC} = [
276 210.4 137.6
69 52.6 34.4

];

var inflow{Product,Plant,DC} >= 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]);
con PlantCon{i in Plant}: sum{l in Product,k in DC}(inflow[l,i,k])<=PlCapacity[i];
con DCCon{l in Product,k in DC}: sum{i in Plant}(inflow[l,i,k])>=Demand[l,k];

solve;
print z inflow ;
quit;

1 REPLY 1
Kurt_Bremser
Super User

Look at your incost dataset. Using just $ defines a variable with a length of 8, which is too short for your values ("Santander" has 9 characters, and the UTF characters in "Medellín" cause the actual data to be longer).

This data step will create a dataset where the rest of the code works:

data incost;
input Product $ Plant :$9. DC :$10. incost;
datalines;
P1 Barranqu Bogotá 130
P1 Barranqu Medellín 90.6
P1 Barranqu Cali 142
P1 Santander Bogotá 53.6
P1 Santander Medellín 41.6
P1 Santander Cali 88.8
P2 Barranqu Bogotá 130
P2 Barranqu Medellín 90.6
P2 Barranqu Cali 142
P2 Santander Bogotá 53.6
P2 Santander Medellín 41.6
P2 Santander Cali 88.8
;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 696 views
  • 0 likes
  • 2 in conversation