NETWORK Procedure

Example 2.14 Shortest Path in a Road Network by Date and Time

This example reconsiders the road network between a SAS employee’s home in Raleigh, North Carolina, and SAS headquarters nearby in Cary introduced in the section Road Network Shortest Path. The following data provide a snapshot of the road network and travel times observed at three different times:

data mylib.LinkSetInRoadNC;
   input start_inter $1-20 end_inter $21-40 miles miles_per_hour
      date date11. time time10.;
   format date date11. time time10.;
   time_to_travel = miles * 1/miles_per_hour * 60;
   datalines;
614CapitalBlvd      Capital/WadeAve      0.6  25 15-APR-2013 10:30 am
614CapitalBlvd      Capital/US70W        0.6  25 15-APR-2013 10:30 am
614CapitalBlvd      Capital/US440W       3.0  45 15-APR-2013 10:30 am
Capital/WadeAve     WadeAve/RaleighExpy  3.0  40 15-APR-2013 10:30 am
Capital/US70W       US70W/US440W         3.2  60 15-APR-2013 10:30 am
US70W/US440W        US440W/RaleighExpy   2.7  60 15-APR-2013 10:30 am
Capital/US440W      US440W/RaleighExpy   6.7  60 15-APR-2013 10:30 am
US440W/RaleighExpy  RaleighExpy/US40W    3.0  60 15-APR-2013 10:30 am
WadeAve/RaleighExpy RaleighExpy/US40W    3.0  60 15-APR-2013 10:30 am
RaleighExpy/US40W   US40W/HarrisonAve    1.3  55 15-APR-2013 10:30 am
US40W/HarrisonAve   SASCampusDrive       0.5  25 15-APR-2013 10:30 am
614CapitalBlvd      Capital/WadeAve      0.6  25 16-APR-2013  9:30 am
614CapitalBlvd      Capital/US70W        0.6  25 16-APR-2013  9:30 am
614CapitalBlvd      Capital/US440W       3.0  45 16-APR-2013  9:30 am
Capital/WadeAve     WadeAve/RaleighExpy  3.0  25 16-APR-2013  9:30 am
Capital/US70W       US70W/US440W         3.2  60 16-APR-2013  9:30 am
US70W/US440W        US440W/RaleighExpy   2.7  60 16-APR-2013  9:30 am
Capital/US440W      US440W/RaleighExpy   6.7  60 16-APR-2013  9:30 am
US440W/RaleighExpy  RaleighExpy/US40W    3.0  60 16-APR-2013  9:30 am
WadeAve/RaleighExpy RaleighExpy/US40W    3.0  60 16-APR-2013  9:30 am
RaleighExpy/US40W   US40W/HarrisonAve    1.3  55 16-APR-2013  9:30 am
US40W/HarrisonAve   SASCampusDrive       0.5  25 16-APR-2013  9:30 am
614CapitalBlvd      Capital/WadeAve      0.6  25 18-APR-2013  8:30 am
614CapitalBlvd      Capital/US440W       3.0  45 18-APR-2013  8:30 am
Capital/WadeAve     WadeAve/RaleighExpy  3.0  25 18-APR-2013  8:30 am
Capital/US440W      US440W/RaleighExpy   6.7  60 18-APR-2013  8:30 am
US440W/RaleighExpy  RaleighExpy/US40W    3.0  60 18-APR-2013  8:30 am
WadeAve/RaleighExpy RaleighExpy/US40W    3.0  60 18-APR-2013  8:30 am
RaleighExpy/US40W   US40W/HarrisonAve    1.3  55 18-APR-2013  8:30 am
US40W/HarrisonAve   SASCampusDrive       0.5  25 18-APR-2013  8:30 am
;

The first snapshot (15-APR-2013 10:30 am) is a typical traffic pattern on a workday. The second snapshot (16-APR-2013 9:30 am) represents morning rush-hour traffic, and the third (18-APR-2013 8:30 am) represents rush-hour traffic where a major highway (US70W) has been closed for repairs.

The following statements find the route that yields the shortest path between home (614 Capital Boulevard) and SAS headquarters (SAS Campus Drive) for all three scenarios simultaneously by using the BY statement:

proc network
   links              = mylib.LinkSetInRoadNC;
   linksVar
      from            = start_inter
      to              = end_inter
      weight          = time_to_travel;
   shortestPath
      outPathsLinks   = mylib.ShortPathP
      outWeights      = mylib.ShortPathW
      source          = "614CapitalBlvd"
      sink            = "SASCampusDrive";
   displayout
      ProblemSummary  = ProblemSummary
      SolutionSummary = SolutionSummary;
   by date time;
run;
%put &_NETWORK_;

Assuming that your grid has a total of at least three cores, all three graphs are processed simultaneously through one call to PROC NETWORK. The progress of the procedure is shown in Output 2.14.1.

Output 2.14.1: PROC NETWORK Log: Shortest Path in a Road Network by Date and Time

NOTE: ------------------------------------------------------------------------------------------
NOTE: Running NETWORK.                                                                          
NOTE: ------------------------------------------------------------------------------------------
NOTE: The number of nodes in the input graph is 10.                                             
NOTE: The number of links in the input graph is 11.                                             
NOTE: Processing the shortest paths problem using 1 threads across 1 machines.                  
NOTE: Processing the shortest paths problem between 1 source nodes and 1 sink nodes.            
NOTE: Processing the shortest paths problem used 0.01 (cpu: 0.00) seconds.                      
NOTE: The above message was for the following BY group:                                         
      date=15-APR-2013 time=10:30:00                                                            
NOTE: The number of nodes in the input graph is 10.                                             
NOTE: The number of links in the input graph is 11.                                             
NOTE: Processing the shortest paths problem using 16 threads across 1 machines.                 
NOTE: Processing the shortest paths problem between 1 source nodes and 1 sink nodes.            
NOTE: Processing the shortest paths problem used 0.00 (cpu: 0.00) seconds.                      
NOTE: The above message was for the following BY group:                                         
      date=16-APR-2013 time=9:30:00                                                             
NOTE: The number of nodes in the input graph is 8.                                              
NOTE: The number of links in the input graph is 8.                                              
NOTE: Processing the shortest paths problem using 2 threads across 1 machines.                  
NOTE: Processing the shortest paths problem between 1 source nodes and 1 sink nodes.            
NOTE: Processing the shortest paths problem used 0.00 (cpu: 0.00) seconds.                      
NOTE: The above message was for the following BY group:                                         
      date=18-APR-2013 time=8:30:00                                                             
NOTE: The Cloud Analytic Services server processed the request in 0.614685 seconds.             
NOTE: The data set MYLIB.SHORTPATHP has 16 observations and 8 variables.                        
NOTE: The data set MYLIB.SHORTPATHW has 3 observations and 5 variables.                         
STATUS=OK  PROBLEM_TYPE=SHORTESTPATH  CPU_TIME=2.17  REAL_TIME=0.61                             


Output 2.14.2 displays the output table mylib.ProblemSummary, which contains a summary of each graph that is processed by PROC NETWORK.

Output 2.14.2: Problem Summary by Date and Time

datetimenumNodesnumLinksgraphDirection
15-APR-201310:30:001011Undirected
16-APR-20139:30:001011Undirected
18-APR-20138:30:0088Undirected


Output 2.14.3 displays the output table mylib.SolutionSummary, which contains a solution summary for the processing on each graph.

Output 2.14.3: Solution Summary by Date and Time

datetimeproblemTypestatusnumPathscpuTimerealTime
15-APR-201310:30:00Shortest PathOK10.000.01
16-APR-20139:30:00Shortest PathOK10.000.00
18-APR-20138:30:00Shortest PathOK10.000.00


Output 2.14.4 displays the output data table mylib.ShortPathW, which shows the total time to travel on the best route for each time snapshot.

Output 2.14.4: Shortest Path Summary for Road Network at Each Date and Time

datetimesourcesinkpath_weight
15-APR-201310:30:00614CapitalBlvdSASCampusDrive11.5582
16-APR-20139:30:00614CapitalBlvdSASCampusDrive12.9582
18-APR-20138:30:00614CapitalBlvdSASCampusDrive14.2582


Output 2.14.5 displays the output data table mylib.ShortPathP, which shows (by date and time) the best route for each time snapshot.

Output 2.14.5: Shortest Path for Road Network by Date and Time

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

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

orderstart_interend_intertime_to_travel
1614CapitalBlvdCapital/WadeAve1.4400
2Capital/WadeAveWadeAve/RaleighExpy7.2000
3WadeAve/RaleighExpyRaleighExpy/US40W3.0000
4RaleighExpy/US40WUS40W/HarrisonAve1.4182
5US40W/HarrisonAveSASCampusDrive1.2000
time  14.2582
date  14.2582
   38.7745


Last updated: August 07, 2026