Network Action Set
Finding the Reach Networks of a Directed Graph
This section contains PROC CAS code.
Note: Input data must be accessible in your CAS session, either as one or more CAS tables or as one or more transient-scope tables. A CAS 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 2, Shared Concepts (SAS Viya: Machine Learning Procedures). A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.
This section illustrates the use of the reach action on the directed graph G shown in Figure 18.
Figure 18: A Directed Graph G

The directed graph G can be represented using the following links data set, LinkSetIn:
data LinkSetIn;
input from $ to $ @@;
datalines;
A B A C A D B C B E
B F C E D E E D E F
F G G H G I H G H I
;
Consider two sets of source nodes, and
. These source node sets can be defined together as follows:
data NodeSubSetIn;
input node $ reach;
datalines;
A 2
C 1
H 2
;
The following DATA steps load the LinkSetIn and NodeSubSetIn data sets into CAS data tables named mylib.LinkSetIn and mylib.NodeSubSetIn. These statements assume that the CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.
data mylib.LinkSetIn;
set LinkSetIn;
run;
data mylib.NodeSubSetIn;
set NodeSubSetIn;
run;
You can use the following statements to find the reach network that is restricted by a hop limit of 1 from both sets of source nodes:
proc cas;
loadactionset "network";
action reach result=r status=s /
direction = "directed"
links = {name = "LinkSetIn"}
nodessubset = {name = "NodeSubSetIn"}
outReachNodes = {name = "ReachNodes", replace=true}
outReachlinks = {name = "ReachLinks", replace=true}
outCounts = {name = "ReachCounts", replace=true}
maxreach = 1;
run;
print r.ProblemSummary; run;
print r.SolutionSummary; run;
action table.fetch / table = "ReachNodes" sortBy = {"reach", "node"}; run;
action table.fetch / table = "ReachLinks" sortBy = {"reach", "from", "to"}; run;
action table.fetch / table = "ReachCounts" sortBy = {"reach", "node"}; run;
quit;
The problem summary output from this action is shown in Output 28.15.1.
Output 28.15.1: Problem Summary
| Problem Summary | |
|---|---|
| Number of Nodes | 9 |
| Number of Links | 15 |
| Graph Direction | Directed |
The solution summary output from this action is shown in Output 28.15.2.
Output 28.15.2: Solution Summary
| Solution Summary | |
|---|---|
| Problem Type | Reach |
| Solution Status | OK |
| CPU Time | 0.01 |
| Real Time | 0.00 |
The output data tables ReachNodes, ReachLinks, and ReachCounts now contain the nodes, links, and counts of the reach networks, respectively, that come from and
. They are shown in Output 28.15.3 through Output 28.15.5.
Output 28.15.3: Reach Networks (Nodes) for and
with Hop Limit of 1
| Selected Rows from Table REACHNODES | ||
|---|---|---|
| _Index_ | reach | node |
| 1 | 1 | C |
| 2 | 1 | E |
| 3 | 2 | A |
| 4 | 2 | B |
| 5 | 2 | C |
| 6 | 2 | D |
| 7 | 2 | G |
| 8 | 2 | H |
| 9 | 2 | I |
Output 28.15.4: Reach Networks (Links) for and
with Hop Limit of 1
| Selected Rows from Table REACHLINKS | |||
|---|---|---|---|
| _Index_ | reach | from | to |
| 1 | 1 | C | E |
| 2 | 2 | A | B |
| 3 | 2 | A | C |
| 4 | 2 | A | D |
| 5 | 2 | B | C |
| 6 | 2 | G | H |
| 7 | 2 | G | I |
| 8 | 2 | H | G |
| 9 | 2 | H | I |
Output 28.15.5: Reach Networks (Counts) for and
with Hop Limit of 1
| Selected Rows from Table REACHCOUNTS | ||||
|---|---|---|---|---|
| _Index_ | reach | node | count | count_not |
| 1 | 1 | C | 2 | 7 |
| 2 | 2 | A | 7 | 2 |
| 3 | 2 | H | 7 | 2 |
Finding the Reach Networks of a 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 accessible to the CAS server. One way to do this is to convert the LinkSetIn data to the comma-separated-value (CSV) file LinkSetIn.csv, convert the NodeSubSetIn data to the CSV file NodeSubSetIn.csv, and then use the following code to load the CSV files into CAS:
s:loadtable{casLib="casuser", path="LinkSetIn.csv"}
s:loadtable{casLib="casuser", path="NodeSubSetIn.csv"}
For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.
You can use the following statements to find the reach network that is restricted by a hop limit of 1 from both sets of source nodes:
s:network_reach{
direction = "directed",
links = {name = "LinkSetIn"},
nodessubset = {name = "NodeSubSetIn"},
outReachNodes = {name = "ReachNodes", replace=true},
outReachlinks = {name = "ReachLinks", replace=true},
outCounts = {name = "ReachCounts", replace=true},
maxreach = 1}
Finding the Reach Networks of a 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 accessible to the CAS server. One way to do this is to convert the LinkSetIn data to the comma-separated-value (CSV) file LinkSetIn.csv, convert the NodeSubSetIn data to the CSV file NodeSubSetIn.csv, and then use the following code to load the CSV files into CAS:
s.upload_file('LinkSetIn.csv')
s.upload_file('NodeSubSetIn.csv')
For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
You can use the following statements to find the reach network that is restricted by a hop limit of 1 from both sets of source nodes:
s.network.reach(
direction = "directed",
links = {"name":"LinkSetIn"},
nodessubset = {"name":"NodeSubSetIn"},
outReachNodes = {"name":"ReachNodes", "replace":True},
outReachLinks = {"name":"ReachLinks", "replace":True},
outCounts = {"name":"ReachCounts", "replace":True},
maxreach = 1)
Finding the Reach Networks of a Directed Graph
This example is not available for the R programming language.