BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mattbuk
Calcite | Level 5

It appears the code won't recognize the date I am inputting in my optimization model. Here is the code:

Data incost;
infile datalines dsd delimiter = '09'x;
input Product $ Factory $ CrossDock $ incost;
datalines;
Stylish 1 CD1 30
Stylish 2 CD1 23
Stylish 3 CD1 35
Stylish 4 CD1 70
Stylish 5 CD1 65
Stylish 1 CD2 50
Stylish 2 CD2 66
Stylish 3 CD2 14
Stylish 4 CD2 12
Stylish 5 CD2 70
Liesure 1 CD1 33
Liesure 2 CD1 25
Liesure 3 CD1 39
Liesure 4 CD1 77
Liesure 5 CD1 12
Liesure 1 CD2 55
Liesure 2 CD2 73
Liesure 3 CD2 15
Liesure 4 CD2 13
Liesure 5 CD2 14


;
Run;
Data outcost;
infile datalines dsd delimiter = '09'x;
input Product $ CrossDock $ DC $ Outcost;
datalines;
Stylish CD1 1 12
Stylish CD1 2 25
Stylish CD1 3 22
Stylish CD1 4 40
Stylish CD1 5 41
Stylish CD2 1 65
Stylish CD2 2 22
Stylish CD2 3 23
Stylish CD2 4 12
Stylish CD2 5 15
Leisure CD1 1 13
Leisure CD1 2 28
Leisure CD1 3 24
Leisure CD1 4 44
Leisure CD1 5 45
Leisure CD2 1 72
Leisure CD2 2 24
Leisure CD2 3 25
Leisure CD2 4 13
Leisure CD2 5 17
;
Run;

proc optmodel;

set Product = {'Stylish','Leisure'};
set Factory= {1,2,3,4,5};
set CrossDock = {'CD1','CD2'};
set DC = {1,2,3,4,5};

number FacCap{Product,Factory} = [
150 200
300 300
90 70
140 30
220 220
];
number Demand{Product,DC}= [
130 45 70 100 5
15 45 40 100 175
];
number TotCap{Factory}=[ 200 300 1000 1000 1000];

number incost{Product,Factory,CrossDock};
Read data inCost into [Product Factory CrossDock]inCost;

number outcost{Product,CrossDock,DC};
Read data outCost into [Product CrossDock DC] outCost;

var Inflow{Product,Factory,CrossDock} >= 0 integer;
var Outflow{Product,CrossDock,DC} >= 0 integer;

min TotalCost = sum{l in Product,i in Factory, j in CrossDock}Inflow[l,i,j]*incost[l,i,j]
+sum{l in Product, j in CrossDock,k in DC}Outflow[l,j,k]*outCost[l,j,k];

con FacConP{i in Factory,l in Product}: sum{j in CrossDock}Inflow[l,i,j]<= FacCap[l,i];
con FacConT{i in Factory}:sum{j in CrossDock,l in product}Inflow[l,i,j]<= TotCap[i];
con DemandCon{k in DC, l in product}: sum{j in CrossDock}Outflow[l,j,k]>= Demand[l,k];
con EqualCon{j in CrossDock,l in Product}:sum{i in Factory}Inflow[l,i,j]=sum{k in DC}Outflow[l,j,k];

solve;
print Inflow Outflow Incost;
quit;

 

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

There are two data issues:

1. Change Liesure to Leisure in the first data set.

2. Your data sets have Factory and DC as strings, but the corresponding OPTMODEL sets are numeric.  One way to correct the type mismatch is to change the DATA step INPUT statements as follows:

   input Product $ Factory CrossDock $ incost;

   input Product $ CrossDock $ DC Outcost;

An alternative approach is to keep the original INPUT statements and instead change the SET declarations to strings:

set Factory= {'1','2','3','4','5'};

set DC = {'1','2','3','4','5'};

View solution in original post

3 REPLIES 3
RobPratt
SAS Super FREQ

There are two data issues:

1. Change Liesure to Leisure in the first data set.

2. Your data sets have Factory and DC as strings, but the corresponding OPTMODEL sets are numeric.  One way to correct the type mismatch is to change the DATA step INPUT statements as follows:

   input Product $ Factory CrossDock $ incost;

   input Product $ CrossDock $ DC Outcost;

An alternative approach is to keep the original INPUT statements and instead change the SET declarations to strings:

set Factory= {'1','2','3','4','5'};

set DC = {'1','2','3','4','5'};
mattbuk
Calcite | Level 5

Hi Rob,

Thank you for your response. The solution worked! I was curious why changing the input statements worked. How did the data types change when I changed the $ symbol location. As you can probably tell, I am vary new to SAS, so an explanation would really help :). Thank you for all the help.

RobPratt
SAS Super FREQ

The $ in the INPUT statement indicates that the variable is character instead of numeric.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 796 views
  • 1 like
  • 2 in conversation