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

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.

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
75
76 proc optmodel;
77
78 set<str> Ports;
79 set<str> DC;
80 set<str> IC;
81
82 num Containers {Ports,DC};
83
84 num InboundLinehaul {Ports, IC};
85
86 num OutboundLinehaul {IC, DC};
87 num MilesBetweenIC_DC {IC, DC};
88 num Outbound_Fuel {IC, DC};
89 num DistanceICtoDC {IC, DC};
90 num handling_cost {IC};
91
92 /*read data into the Containers parameter*/
93
94 read data PUBLIC.FinalData into [Origin_Port_Code DCCode] Containers=NET_FEU;
ERROR: The symbol 'Ports' has no value at line 82 column 17.
NOTE: There were 1 observations read from the data set PUBLIC.FINALDATA.
95
96
97 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

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.

View solution in original post

8 REPLIES 8
RobPratt
SAS Super FREQ

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:

https://go.documentation.sas.com/?docsetId=ormpug&docsetTarget=ormpug_optmodel_examples07.htm&docset...

 

As a new user, you might also be interested in this book of examples;

https://go.documentation.sas.com/?docsetId=ormpex&docsetTarget=titlepage.htm&docsetVersion=15.1&loca...

Santha
Pyrite | Level 9

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

 

RobPratt
SAS Super FREQ

What did you try, and what error messages did you get?

Santha
Pyrite | Level 9

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:

OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
75
76 proc optmodel;
77
78 set<str> Ports;
79 set<str> DC;
80 set<str> IC;
81 num Containers {Ports,DC};
82
83 /*num InboundLinehaul {Ports, IC};
84
85 num OutboundLinehaul {IC, DC};
86 num MilesBetweenIC_DC {IC, DC};
87 num Outbound_Fuel {IC, DC};
88 num DistanceICtoDC {IC, DC};
89 num handling_cost {IC};*/
90
91 /*read data into the Containers parameter*/
92
93 read data PUBLIC.FinalData_for_SAS into Ports [Origin_Port_Code]=Origin_Port_Code;
-----------------
525 616
----------------
582
ERROR 525-782: The symbol 'Origin_Port_Code' is unknown.
ERROR 616-782: The name 'Ports' must be an array.
ERROR 582-782: The target 'Ports' must be numeric or string, found a set.
94
95 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
RobPratt
SAS Super FREQ

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.

Santha
Pyrite | Level 9

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. 

RobPratt
SAS Super FREQ

Glad to help.  No, there is no such DISTINCT keyword for READ DATA, but the resulting set always contains only distinct values.

Santha
Pyrite | Level 9

THanks a ton

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 8 replies
  • 1297 views
  • 2 likes
  • 2 in conversation