Network Action Set

Finding the Maximal Cliques of an Undirected Graph

This section contains PROC CAS code.

Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. 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 clique action on the undirected graph G shown in Figure 4.

Figure 4: An Undirected Graph G

An Undirected Graph


The undirected graph G can be represented by the following links data set, LinkSetIn:

data LinkSetIn;
   input from to @@;
   datalines;
0 1  0 2  0 3  0 4  0 5
0 6  1 2  1 3  1 4  2 3
2 4  2 5  2 6  2 7  2 8
3 4  5 6  7 8  8 9
;

The following DATA step loads the LinkSetIn data set into a CAS data table named 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.LinkSetIn;
   set LinkSetIn;
run;

The following statements calculate the maximal cliques and output the results in the data table Cliques:

proc cas;
   loadactionset "network";
   action network.clique result=r status=s /
      indexOffset = 1
      links       = {name = "LinkSetIn"}
      out         = {name = "Cliques", replace=true}
      maxCliques  = "all";
   run;
   print r.ProblemSummary; run;
   print r.SolutionSummary; run;
   action table.fetch / table = "Cliques" sortBy = "clique"; run;
quit;

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

Output 28.4.1: Problem Summary

Problem Summary
Number of Nodes10
Number of Links19
Graph DirectionUndirected


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

Output 28.4.2: Solution Summary

Solution Summary
Problem TypeClique
Solution StatusOK
Number of Cliques4
CPU Time0.00
Real Time0.00


The output data table Cliques now contains the maximal cliques of the input graph, as shown in Output 28.4.3.

Output 28.4.3: Maximal Cliques of an Undirected Graph

Selected Rows from Table CLIQUES
_Index_cliquenode
111
213
314
410
512
622
720
826
925
1037
1138
1232
1349
1448


The maximal cliques are shown graphically in Output 28.4.4 and Output 28.4.5.

Output 28.4.4: Maximal Cliques upper C Superscript 1 and upper C squared

upper C Superscript 1 Baseline equals StartSet 0 comma 1 comma 2 comma 3 comma 4 EndSet upper C squared equals StartSet 0 comma 2 comma 5 comma 6 EndSet
clique1_1 clique1_2


Output 28.4.5: Maximal Cliques upper C cubed and upper C Superscript 4

upper C cubed equals StartSet 2 comma 7 comma 8 EndSet upper C Superscript 4 Baseline equals StartSet 8 comma 9 EndSet
clique1_3 clique1_4


Finding the Maximal Cliques 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 LinkSetIn data to the comma-separated-value (CSV) file LinkSetIn.csv and then use the following code to load the CSV file into CAS:

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 maximal cliques and output the results in the data table Cliques:

s:network_clique{
   indexOffset = 1,
   links       = {name = "LinkSetIn"},
   out         = {name = "Cliques", replace=true},
   maxCliques  = "all"}

Finding the Maximal Cliques 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 LinkSetIn data to the comma-separated-value (CSV) file LinkSetIn.csv and then use the following code to load the CSV file into CAS:

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 maximal cliques and output the results in the data table Cliques:

s.network.clique(
    indexOffset = 1,
    links       = {"name": "LinkSetIn"},
    out         = {"name": "Cliques", "replace":True},
    maxCliques  = "all")

Finding the Maximal Cliques of an Undirected Graph

This example is not available for the R programming language.

Last updated: March 12, 2026