Network Action Set

Network Projection of a Bipartite 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 provides a simple example that calculates a network projection of the bipartite graph G that is shown in Figure 16.

Figure 16: Undirected Graph G

Undirected Graph


The bipartite graph G can be represented by the links data table. You can create this table, mycas.LinkSetIn, by using the following DATA step:

data mycas.LinkSetIn;
   input from $ to $ @@;
   datalines;
A 1  A 2  A 3
B 1  B 2  B 4  B 5
C 2  C 3  C 4  C 5
D 3  D 5
E 4  E 5  E 6
;

In order to identify the partition of each node, you must also specify a nodes data table, mycas.NodeSetIn, which you can create using the following DATA step:

data mycas.NodeSetIn;
   input node $ partitionFlag @@;
   datalines;
A 1  B 1  C 1  D 1  E 1
1 0  2 0  3 0  4 0  5 0  6 0
;

The following statements find the projection of the network onto nodes A through E:

proc cas;
   loadactionset "network";
   action projection result=r status=s /
      links               = {name = "LinkSetIn"}
      nodes               = {name = "NodeSetIn"}
      partition           = "partitionFlag"
      outProjectionLinks  = {name = "ProjLinkSetOut", replace=true}
      commonNeighbors     = true;
   run;
   print r.ProblemSummary; run;
   print r.SolutionSummary; run;
   action table.fetch / table = "ProjLinkSetOut" sortBy = {"from","to"}; run;
quit;

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

Output 28.14.1: Problem Summary

Selected Rows from Table PROJLINKSETOUT
_Index_fromtocommonNeighbors
1AB2
2AC2
3AD1
4BC3
5BD1
6BE2
7CD2
8CE2
9DE1


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

Output 28.14.2: Solution Summary

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


The output data table ProjLinkSetOut, as shown in Output 28.14.3, contains the links of the projected graph. For each link, the number of neighbors that connect the from and to nodes is given in the commonNeighbors variable.

Output 28.14.3: Links of the Projected Graph

Selected Rows from Table PROJLINKSETOUT
_Index_fromtocommonNeighbors
1AB2
2AC2
3AD1
4BC3
5BD1
6BE2
7CD2
8CE2
9DE1


The projected graph is shown in Figure 17.

Figure 17: The Projected Graph

The Projected Graph


Network Projection of a Bipartite 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 NodeSetIn data to the CSV file NodeSetIn.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="NodeSetIn.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 find the projection of the network onto nodes A through E:

s:network_projection{
   links              = {name = "LinkSetIn"},
   nodes              = {name = "NodeSetIn"},
   partition          = "partitionFlag",
   outProjectionLinks = {name = "ProjLinkSetOut", replace=true},
   commonNeighbors    = true}

Network Projection of a Bipartite 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 NodeSetIn data to the CSV file NodeSetIn.csv, and then use the following code to load the CSV files into CAS:

s.upload_file('LinkSetIn.csv')
s.upload_file('NodeSetIn.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 find the projection of the network onto nodes A through E:

s.network.projection(
    links              = {"name":"LinkSetIn"},
    nodes              = {"name":"NodeSetIn"},
    partition          = "partitionFlag",
    outProjectionLinks = {"name":"ProjLinkSetOut", "replace":True},
    commonNeighbors    = True)

Network Projection of a Bipartite Graph

This example is not available for the R programming language.

Last updated: March 12, 2026