NETWORK Procedure

Road Network Shortest Path

Consider the following road network between a SAS employee’s home in Raleigh, North Carolina, and SAS headquarters nearby in Cary. In this road network (graph), the links are the roads and the nodes are intersections of the roads. For each road, you assign a link attribute in the variable time_to_travel to describe the number of minutes that it takes to drive from one node to another. The following data were collected using Google Maps (Google 2011), which gives an approximate number of minutes to travel between two nodes based on the length of the road and the typical speed during normal traffic patterns. These statements assume that the CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.

data mylib.LinkSetInRoadNC10am;
   input start_inter $1-20 end_inter $21-40 miles miles_per_hour;
   time_to_travel = miles * 1/miles_per_hour * 60;
   datalines;
614CapitalBlvd      Capital/WadeAve      0.6  25
614CapitalBlvd      Capital/US70W        0.6  25
614CapitalBlvd      Capital/US440W       3.0  45
Capital/WadeAve     WadeAve/RaleighExpy  3.0  40
Capital/US70W       US70W/US440W         3.2  60
US70W/US440W        US440W/RaleighExpy   2.7  60
Capital/US440W      US440W/RaleighExpy   6.7  60
US440W/RaleighExpy  RaleighExpy/US40W    3.0  60
WadeAve/RaleighExpy RaleighExpy/US40W    3.0  60
RaleighExpy/US40W   US40W/HarrisonAve    1.3  55
US40W/HarrisonAve   SASCampusDrive       0.5  25
;

Using PROC NETWORK, you want to find the route that yields the shortest path between home (614 Capital Boulevard) and SAS headquarters (SAS Campus Drive). This can be done using the SHORTESTPATH statement as follows:

proc network
   links            = mylib.LinkSetInRoadNC10am;
   linksVar
      from          = start_inter
      to            = end_inter
      weight        = time_to_travel;
   shortestPath
      outPathsLinks = mylib.ShortPath
      source        = "614CapitalBlvd"
      sink          = "SASCampusDrive";
run;

For more information about shortest path algorithms in PROC NETWORK, see the section Shortest Path. Figure 1 displays the output data table mylib.ShortPath, which shows the best route to take to minimize travel time at 10:00 a.m. on a workday. This route is also shown in Google Maps in Figure 2.

Figure 1: Shortest Path for Road Network at 10:00 A.M.

orderstart_interend_intertime_to_travel
1614CapitalBlvdCapital/WadeAve1.4400
2Capital/WadeAveWadeAve/RaleighExpy4.5000
3WadeAve/RaleighExpyRaleighExpy/US40W3.0000
4RaleighExpy/US40WUS40W/HarrisonAve1.4182
5US40W/HarrisonAveSASCampusDrive1.2000
   11.5582


Figure 2: Shortest Path for Road Network at 10:00 A.M. in Google Maps

Shortest Path for Road Network at 10:00 A.M. in Google Maps


Now suppose that it is the evening rush hour (5:00–7:00 p.m.) and the time that it takes to travel this route has changed because of traffic patterns. You want to find the route that is the shortest path for going home from SAS headquarters under different speed assumptions because of rush-hour traffic. The following data table lists approximate travel times and speeds for driving in the opposite direction:

data mylib.LinkSetInRoadNC5pm;
   input start_inter $1-20 end_inter $21-40 miles miles_per_hour;
   time_to_travel = miles * 1/miles_per_hour * 60;
   datalines;
614CapitalBlvd      Capital/WadeAve      0.6  25
614CapitalBlvd      Capital/US70W        0.6  25
614CapitalBlvd      Capital/US440W       3.0  45
Capital/WadeAve     WadeAve/RaleighExpy  3.0  25 /*high traffic*/
Capital/US70W       US70W/US440W         3.2  60
US70W/US440W        US440W/RaleighExpy   2.7  60
Capital/US440W      US440W/RaleighExpy   6.7  60
US440W/RaleighExpy  RaleighExpy/US40W    3.0  60
WadeAve/RaleighExpy RaleighExpy/US40W    3.0  60
RaleighExpy/US40W   US40W/HarrisonAve    1.3  55
US40W/HarrisonAve   SASCampusDrive       0.5  25
;

The following statements are similar to those in the first PROC NETWORK run, except that they use the data table mylib.LinkSetInRoadNC5pm and the SOURCE= and SINK= option values are reversed:

proc network
   links            = mylib.LinkSetInRoadNC5pm;
   linksVar
      from          = start_inter
      to            = end_inter
      weight        = time_to_travel;
   shortestPath
      outPathsLinks = mylib.ShortPath
      source        = "SASCampusDrive"
      sink          = "614CapitalBlvd";
run;

Now, the output data table mylib.ShortPath, shown in Figure 3, shows the best route for going home. Because the traffic on Wade Avenue is usually heavy at this time of day, the best route home is different from the best route to work.

Figure 3: Shortest Path for Road Network at 5:00 P.M.

orderstart_interend_intertime_to_travel
1US40W/HarrisonAveSASCampusDrive1.2000
2RaleighExpy/US40WUS40W/HarrisonAve1.4182
3US440W/RaleighExpyRaleighExpy/US40W3.0000
4US70W/US440WUS440W/RaleighExpy2.7000
5Capital/US70WUS70W/US440W3.2000
6614CapitalBlvdCapital/US70W1.4400
   12.9582


This new route is shown in Google Maps in Figure 4.

Figure 4: Shortest Path for Road Network at 5:00 P.M. in Google Maps

Shortest Path for Road Network at 5:00 P.M. in Google Maps


Last updated: August 07, 2026