Hi
I am a first time SAS User and this is my first model. I am trying to use proc optmodel. Here is my code below. My objectives are two (a) To define a index set called "Ports" that will be the unique Ports that I see in my datafile. (b) To populate the Array called Containers (that is indexed over Ports and DC) with NET_FEU(that is a measure in the dataset).
proc optmodel;
set<str> Ports;
set<str> DC;
set<str> IC;
num Containers {Ports,DC};
/*read data into the Containers parameter*/
read data PUBLIC.FinalData into [Origin_Port_Code DCCode] Containers=NET_FEU;
I am getting an error. Here is my error log. I appreciate any help in this regard.
Correct syntax is:
read data PUBLIC.FinalData_for_SAS into Ports=[Origin_Port_Code];
It sounds like from your description that there are duplicate values, and you will get warnings about that. To avoid the warnings, you can instead create another data set (before calling PROC OPTMODEL) that contains only one column, with distinct values for Origin_Port_Code.
The numeric parameter Containers is indexed by Ports and DC, and both sets need to be populated before you can assign values to Containers. Here are two alternative ways to deal with this.
1. Populate Ports and DC, perhaps with separate READ DATA statements, before the READ DATA that gave the error.
2. Reindex Containers to depend on a sparse set of pairs, as in this documentation example:
As a new user, you might also be interested in this book of examples;
Rob
Thank you very much for your quick reply. Can you tell me how do I populate Ports and Containers. I tried to read from dataset but I was not successful. When I have my Ports and DCs populated, I will expect the containers to be read as you said.
Can you help me on this?
Thanks
What did you try, and what error messages did you get?
Hi Rob. I tried the below code. I dont know what mistake I am doing.
proc optmodel;
set<str> Ports;
set<str> DC;
set<str> IC;
num Containers {Ports,DC};
/*num InboundLinehaul {Ports, IC};
num OutboundLinehaul {IC, DC};
num MilesBetweenIC_DC {IC, DC};
num Outbound_Fuel {IC, DC};
num DistanceICtoDC {IC, DC};
num handling_cost {IC};*/
/*read data into the Containers parameter*/
read data PUBLIC.FinalData_for_SAS into Ports [Origin_Port_Code]=Origin_Port_Code;
Error Log:
Correct syntax is:
read data PUBLIC.FinalData_for_SAS into Ports=[Origin_Port_Code];
It sounds like from your description that there are duplicate values, and you will get warnings about that. To avoid the warnings, you can instead create another data set (before calling PROC OPTMODEL) that contains only one column, with distinct values for Origin_Port_Code.
Rob. You are just awesome.
Thank you,. Yes i did get duplicates. Is there a way to read only distinct values only? (like in sql - select distinct). if not, i can create a list of unique ports. Thank you. I am going to spend time on learning the link that you provided earlier. IT is very useful.
Glad to help. No, there is no such DISTINCT keyword for READ DATA, but the resulting set always contains only distinct values.
THanks a ton
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.