Network Action Set
Calculating the Core Decomposition of an Undirected 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 example illustrates the use of the core decomposition algorithm on the undirected graph G shown in Figure 7.
Figure 7: An Undirected Graph

The undirected graph G can be represented using the following nodes data set, NodeSetIn, and links data set, LinkSetIn:
data NodeSetIn;
input node $ @@;
datalines;
v1 v2 v3 v4 v5
v6 v7 v8 v9 v10
v11 v12 v13 v14 v15
v16 v17 v18 v19
;
data LinkSetIn;
input from $ to $ @@;
datalines;
v1 v2 v5 v6 v6 v7 v7 v8 v10 v11
v2 v3 v3 v4 v2 v4 v8 v9 v9 v10
v8 v18 v10 v12 v13 v14 v13 v15 v13 v16
v13 v17 v14 v15 v14 v16 v14 v17 v15 v16
v15 v17 v16 v17 v18 v13 v18 v17 v18 v16
v12 v14 v12 v15 v12 v16
;
The following DATA steps load the NodeSetIn and LinkSetIn data sets into CAS data tables named mycas.NodeSetIn and 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.NodeSetIn;
set NodeSetIn;
run;
data mycas.LinkSetIn;
set LinkSetIn;
run;
The following statements calculate the core decomposition and output the results in the data table NodeSetOut:
proc cas;
loadactionset "network";
action network.core result=r status=s /
links = {name = "LinkSetIn"}
nodes = {name = "NodeSetIn"}
outNodes = {name = "NodeSetOut", replace=true};
run;
print r.ProblemSummary; run;
print r.SolutionSummary; run;
action table.fetch / table = "NodeSetOut" sortBy = "core_out"; run;
quit;
The problem summary output from this action is shown in Output 28.7.1.
Output 28.7.1: Problem Summary
| Problem Summary | |
|---|---|
| Number of Nodes | 19 |
| Number of Links | 28 |
| Graph Direction | Undirected |
The solution summary output from this action is shown in Output 28.7.2.
Output 28.7.2: Solution Summary
| Solution Summary | |
|---|---|
| Problem Type | Core Decomposition |
| Solution Status | OK |
| CPU Time | 0.00 |
| Real Time | 0.00 |
The nodes output data table NodeSetOut contains the core number (variable core_out) for each node, as shown in Output 28.7.3.
Output 28.7.3: Core Decomposition of an Undirected Graph
| Selected Rows from Table NODESETOUT | ||
|---|---|---|
| _Index_ | node | core_out |
| 1 | v19 | 0 |
| 2 | v7 | 1 |
| 3 | v1 | 1 |
| 4 | v11 | 1 |
| 5 | v5 | 1 |
| 6 | v6 | 1 |
| 7 | v4 | 2 |
| 8 | v3 | 2 |
| 9 | v10 | 2 |
| 10 | v9 | 2 |
| 11 | v8 | 2 |
| 12 | v2 | 2 |
| 13 | v12 | 3 |
| 14 | v18 | 3 |
| 15 | v15 | 4 |
| 16 | v14 | 4 |
| 17 | v13 | 4 |
| 18 | v17 | 4 |
| 19 | v16 | 4 |
Figure 8 shows the graph layered by its core number.
Figure 8: Core Decomposition

Calculating the Core Decomposition of an Undirected 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 NodeSetIn data to the comma-separated-value (CSV) file NodeSetIn.csv, convert the LinkSetIn data to the CSV file LinkSetIn.csv, and then use the following code to load the CSV files into CAS:
s:loadtable{casLib="casuser", path="NodeSetIn.csv"}
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 core decomposition and output the results in the data table NodeSetOut:
s:network_core{
links = {name = "LinkSetIn"},
nodes = {name = "NodeSetIn"},
outNodes = {name = "NodeSetOut", replace=true}}
Calculating the Core Decomposition of an Undirected 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 NodeSetIn data to the comma-separated-value (CSV) file NodeSetIn.csv, convert the LinkSetIn data to the CSV file LinkSetIn.csv, and then use the following code to load the CSV files into CAS:
s.upload_file('NodeSetIn.csv')
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 core decomposition and output the results in the data table NodeSetOut:
s.network.core(
links = {"name": "LinkSetIn"},
nodes = {"name": "NodeSetIn"},
outNodes = {"name": "NodeSetOut", "replace":True})
Calculating the Core Decomposition of an Undirected Graph
This example is not available for the R programming language.