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

Hi I'm running PROC OPTMODEL with internal data and data thr' read data X into X but after long struggle I'm not able to as SAS is not throwing any error and according to me logic is same for both the methods.
I'm pasting both code with and without read data into

plz let me know where i'm making error

data thr read data into (This does not works):

     Data Products;
        input Product $ Demand Ethiopia Tanzania Nigeria;
        datalines;
    Ginko 550 21.00 22.50   23.00
    Kola  450 22.50 24.50   25.50
    ;

    data Locations;
input Location $ Capacity;
datalines;
 Ethiopia 425 
 Tanzania 400
 Nigeria  750 
 ;

  PROC OPTMODEL ;
SET <string> Locations;
SET <string> Products;
number cost{Products, Locations};
number Capacity{Locations};
number Demand{Products};
var Amount{Products, Locations} >= 0;
minimize ProdCost = sum { i in Products} sum {j in Locations} Amount[i,j]*cost[i,j];
con PlantCapacity {j in Locations}  :   sum{i in Products}Amount[i,j] <= Capacity[j];
con ProductDemand {i in Products}   :   sum{j in Locations}Amount[i,j] >= Demand[i];
read data Locations into Locations=[Location] Capacity=Capacity;
read data Products into Products=[Product] Demand = Demand
{j in Locations} < cost[Product, j] = col(j) >;
print ProdCost;
print Amount;   
print cost;
print Capacity;
print Demand;
  QUIT;

data internally read (But this Works):

    proc optmodel;
     set Products = {"Ginko","Kola"};
     set Locations= {"Ethiopia", "Tanzania", "Nigeria"};
     number Costs{Products, Locations} = [
        21.00 22.50     23.00
        22.50 24.50     25.50 ];
     number Capacity{Locations} = [425 400 750];
     number Demand{Products} = [550 450];
     var Amount{Products, Locations} >= 0;
     minimize z = sum{i in Products}sum{j in Locations}Costs[i, j]*Amount[i,j];
     con CapacityC{j in Locations}: sum{i in Products}Amount[i,j] <= Capacity[j];
     con DemandC{i in Products}: sum{j in Locations}Amount[i,j] >= Demand[i];
   solve;
   print Amount z;
   quit;
1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

Seems fine to me, except that you omitted a SOLVE statement.

View solution in original post

3 REPLIES 3
Reeza
Super User

Post your log from non working code. 

RobPratt
SAS Super FREQ

Seems fine to me, except that you omitted a SOLVE statement.

makarand
Obsidian | Level 7
Ohh...
That's a shame

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Discussion stats
  • 3 replies
  • 1274 views
  • 1 like
  • 3 in conversation