The Network Action Set
Example 16.15 Calculating the Transitive Closure of a Simple Directed Graph
Calculating the Transitive Closure of a Simple Directed Graph
This section contains PROC CAS code.
Note: Input data must be in a CAS table that is accessible in your CAS session. This table has a two-level name; the first level is your CAS engine libref and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 3: Shared Concepts in SAS Visual Data Mining and Machine Learning 8.3: Procedures Guide. For more information about PROC CAS and programming in CASL, see Getting Started with CASL, SAS Cloud Analytic Services: CAS Procedure Programming Guide and Reference, and SAS Viya: System Programming Guide.
This example illustrates the use of the transitive closure algorithm on the simple directed graph G shown in Figure 16.16.
Figure 16: A Simple Directed Graph G

The directed graph G can be represented by the following links data set, LinkSetIn:
data LinkSetIn; input from $ to $ @@; datalines; B C B D C B D A D C ;
The following DATA step loads the LinkSetIn data set into a CAS data table named mycas.LinkSetIn. These statements assume that the CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.
data mycas.LinkSetIn; set LinkSetIn; run;
The following statements calculate the transitive closure and output the results in the data table TransClosure:
proc cas;
loadactionset "network";
action network.transitiveClosure result=r status=s /
direction = "directed"
links = {name = "LinkSetIn"}
out = {name = "TransClosure", replace=true};
run;
print r.ProblemSummary; run;
print r.SolutionSummary; run;
action table.fetch / table = "TransClosure"; run;
quit;
The problem summary output from this action is presented in Output 16.15.1.
Output 16.15.1: Problem Summary
The solution summary output from this action is presented in Output 16.15.2.
Output 16.15.2: Solution Summary
The output data table TransClosure contains the transitive closure of G, as shown in Output 16.15.3.
Output 16.15.3: Transitive Closure of a Simple Directed Graph
The transitive closure of G is shown graphically in Figure 16.17.
Figure 17: Transitive Closure of G

Calculating the Transitive Closure of a Simple Directed Graph
This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be loaded into CAS. One way to do this is to convert the LinkSetIn data to the comma-separated-value (CSV) file LinkSetIn.csv and then use the following code to load the CSV file into CAS:
s:loadtable{casLib="casuser", path="LinkSetIn.csv"}
For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.
The following statements calculate the transitive closure and output the results in the data table TransClosure:
s:network_transitiveClosure{
direction = "directed",
links = {name = "LinkSetIn"},
out = {name = "TransClosure", replace=true}}
Calculating the Transitive Closure of a Simple Directed Graph
This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be loaded into CAS. One way to do this is to convert the LinkSetIn data to the comma-separated-value (CSV) file LinkSetIn.csv and then use the following code to load the CSV file into CAS:
s.upload_file('LinkSetIn.csv')
For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
The following statements calculate the transitive closure and output the results in the data table TransClosure:
s.network.transitiveClosure(
direction = "directed",
links = {"name": "LinkSetIn"},
out = {"name": "TransClosure", "replace":True})
Calculating the Transitive Closure of a Simple Directed Graph
This example is not available for the R programming language.