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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 811 views
  • 1 like
  • 3 in conversation