Network Action Set

Calculating the Summary Statistics 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 calculation of summary statistics on the directed graph G shown in Figure 22.

Figure 22: A Directed Graph G

A Directed Graph


You can represent the directed graph G by using the following nodes data set, NodeSetIn, and links data set, LinkSetIn:

data NodeSetIn;
  input node $ @@;
  datalines;
A B C D E F G H I J K L M N O P
;
data LinkSetIn;
   input from $ to $ weight @@;
   datalines;
A B 1 A C 2 A D 2 B A 2 D E 2
D F 1 E F 2 F D 2 F E 1 A A 2
A B 2 I J 5 K L 3 K M 2 N O 1
P O 5
;

The following DATA steps load the NodeSetIn and LinkSetIn data sets into CAS data tables named mylib.NodeSetIn and mylib.LinkSetIn. These statements assume that the CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.

data mylib.NodeSetIn;
   set NodeSetIn;
run;
data mylib.LinkSetIn;
   set LinkSetIn;
run;

The following statements calculate the default summary statistics and produce information about the connectedness of the graph. They output the results in the data tables NodeSetOut and Summary.

proc cas;
   loadactionset "network";
   action network.summary result=r status=s /
      direction   = "directed"
      indexOffset = 1
      nodes       = {name = "NodeSetIn"}
      links       = {name = "LinkSetIn"}
      outNodes    = {name = "NodeSetOut", replace=true}
      out         = {name = "Summary", replace=true}
      connectedComponents = true;
  run;
  print r.ProblemSummary; run;
  print r.SolutionSummary; run;
  action table.fetch / table = "NodeSetOut"; run;
  action table.fetch / table = "Summary"; run;
quit;

The problem summary output from this action is shown in Output 28.19.1.

Output 28.19.1: Problem Summary

Problem Summary
Number of Nodes16
Number of Links16
Graph DirectionDirected


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

Output 28.19.2: Solution Summary

Solution Summary
Problem TypeSummary
Solution StatusOK
CPU Time0.00
Real Time0.00


The output data table NodeSetOut contains the node-level summary metrics of the input graph, as shown in Output 28.19.3.

Output 28.19.3: Node-Level Graph Summary and Connectedness Statistics of a Directed Graph

Selected Rows from Table NODESETOUT
_Index_nodeleaf_nodesingleton_nodeneighbor_leaf_nodesisolated_star_outisolated_star_inisolated_pairsum_in_and_out_wt
1A001...13
2B000...5
3C100...2
4D000...7
5E000...5
6F000...6
7G010...0
8H010...0
9I001..15
10J100..15
11K0021..5
12L1001..3
13M1001..2
14N001.1.1
15O100.1.6
16P001.1.5


The output data table Summary contains the summary statistics of the input graph, as shown in Output 28.19.4.

Output 28.19.4: Graph Summary and Connectedness Statistics of a Directed Graph

Selected Rows from Table SUMMARY
_Index_nodeslinksavg_links_per_nodedensityself_links_ignoreddup_links_ignoredleaf_nodessingleton_nodesconcompisolated_pairsisolated_stars_outisolated_stars_in
1161610.0666666667005213111


Calculating the Summary Statistics 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 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 default summary statistics and produce information about the connectedness of the graph. They output the results in the data tables NodeSetOut and Summary.

s:network_summary{
   direction   = "directed",
   indexOffset = 1,
   nodes       = {name = "NodeSetIn"},
   links       = {name = "LinkSetIn"},
   outNodes    = {name = "NodeSetOut", replace=true},
   out         = {name = "Summary", replace=true},
   connectedComponents = true}

Calculating the Summary Statistics 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 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 default summary statistics and produce information about the connectedness of the graph. They output the results in the data tables NodeSetOut and Summary.

s.network.summary(
    direction   = "directed",
    indexOffset = 1,
    nodes       = {"name": "NodeSetIn"},
    links       = {"name": "LinkSetIn"},
    outNodes    = {"name": "NodeSetOut", "replace":True},
    out         = {"name": "Summary", "replace":True},
    connectedComponents = True)

Calculating the Summary Statistics of a Directed Graph

This example is not available for the R programming language.

Last updated: March 12, 2026