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

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 Nodes19
Number of Links28
Graph DirectionUndirected


The solution summary output from this action is shown in Output 28.7.2.

Output 28.7.2: Solution Summary

Solution Summary
Problem TypeCore Decomposition
Solution StatusOK
CPU Time0.00
Real Time0.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_nodecore_out
1v190
2v71
3v11
4v111
5v51
6v61
7v42
8v32
9v102
10v92
11v82
12v22
13v123
14v183
15v154
16v144
17v134
18v174
19v164


Figure 8 shows the graph layered by its core number.

Figure 8: Core Decomposition

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.

Last updated: August 04, 2026