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

Hi Geeks,


I am trying to run SAS OPTGRAPH Procedure as to learn more about Travelling Salesman problem (for ShortestPath) using SAS 9.2 version but unfortunately I keep getting "ERROR: 22-322, Expecting an Integer Constant" where more details of this error is in the attached picture. 


I followed the same instructions in this SAS Support Forum .


The sample data includes two nodes (the starting point which is classified as "FROM" and the end point classified as "TO") in addition to the weight of this transaction coded as below:


STEP 1:  Loading the data

data LinkSetIn;input from $ to $ weight @@;datalines;A B 1.0 A C 1.0 A D 1.5 B C 2.0 B D 4.0B E 3.0 C D 3.0 C F 3.0 C H 4.0 D E 1.5D F 3.0 D G 4.0 E F 1.0 E G 1.0 F G 2.0F H 4.0 H I 3.0 I J 1.0 C J 5.0 F J 3.0F I 1.0 H J 1.0;



proc optgraphloglevel = moderatedata_links = LinkSetInout_nodes = NodeSetOut;tspout = TSPTour;run;%put &_OPTGRAPH_;%put &_OPTGRAPH_TSP_;


and the error is: 


Super User

There is no need to go through extra steps to make images of logs and paste them. Best is to copy directly from the log and then paste into a code window opened with either of  the forums {I} or "running man" icons.


The error about the expected integer constant means that the procedure is looking for just that: a number such as



The "out of order" error often is associated with placing a semicolon before a Proc option. The ; would end the procedure statement so the option is not valid in the location of the code encountered.


The TSP statement was not added to PROC OPTGRAPH until version 12.3 (SAS 9.4):


You can also access the TSP algorithm via PROC OPTNET or PROC OPTMODEL (solve with network) in SAS/OR, or via PROC OPTNETWORK or the Network Optimization action set in SAS Optimization on SAS Viya.



Obsidian | Level 7

Thanks for this useful reply but when I ran PROC OPTNET I keep getting "ERROR: Procedure Not Found", it seems that it is also supported from 9.3 (where I have 9.2) Right?


For PROC OPTMODEL , I followed the same instructions as in this SAS Support TSP:


data LinkSetIn;
   input from $ to $ weight @@;
A B 1.0   A C 1.0   A D 1.5   B C 2.0   B D 4.0
B E 3.0   C D 3.0   C F 3.0   C H 4.0   D E 1.5
D F 3.0   D G 4.0   E F 1.0   E G 1.0   F G 2.0
F H 4.0   H I 3.0   I J 1.0   C J 5.0   F J 3.0
F I 1.0   H J 1.0

proc optmodel;
   set<str,str> EDGES;
   set<str> NODES = union{<i,j> in EDGES} {i,j};
   num weight{EDGES};
   read data LinkSetIn into EDGES=[from to] weight;
   num tsp_order{NODES};
   set<str,str> TOUR;

   solve with NETWORK /
      loglevel = moderate
      links    = (weight=weight)
      out      = (order=tsp_order tour=TOUR)

   put TOUR;
   print {<i,j> in TOUR} weight;
   print tsp_order;
   create data NodeSetOut from [node] tsp_order;
   create data TSPTour from [from to]=TOUR weight;

but I got the following error as well:




PROC OPTNET was released in August 2012 with SAS/OR 12.1 (on SAS 9.3M1).


The SOLVE WITH NETWORK statement was added to PROC OPTMODEL in December 2013 with SAS/OR 13.1 (on SAS 9.4M1).


I would strongly recommend that you upgrade to the latest release (SAS/OR 14.3 on SAS 9.4M5) to take advantage of these features and to benefit from the significant performance improvements over the last several years.  Until then, you might be interested in the subtour formulation from this SAS/OR 9.22 example:

Obsidian | Level 7

Thanks again for your reply,


I checked this article before, but the library at is not found. This is where I should start.


Obsidian | Level 7

The forum has more restricted roles to post a question. For the out of order, the code was retrieved from SAS support documentation. The problem might be related to SAS version 9.2 which TSP has been supported since 9.4


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
  • 7 replies
  • 3 in conversation