NETWORK Procedure

Example 2.8 Centrality Metrics for an Undirected Graph by Community

When you are trying to understand the roles of certain entities in a social network, a typical workflow is to first divide the network into communities and then calculate centrality metrics on the induced subgraphs defined by those communities. You can process these induced subgraphs of the original input graph with only one call to PROC NETWORK by using the BY statement. This section presents an example of how to use the COMMUNITY statement, followed by the CENTRALITY statement in conjunction with the BY statement.

Consider the graph depicted in Figure 226.

Figure 226: Undirected Graph

Undirected Graph


The following statements create the data table mylib.LinkSetIn:

data mylib.LinkSetIn;
   input from $ to $ @@;
   datalines;
A B  A C  A D  B C  C D
C E  D F  F G  F H  F I
G H  G I  I J  J K  J L
K L
;

First, call the community detection method as follows:

proc network
   links     = mylib.LinkSetIn
   outNodes  = mylib.OutNodesComms
   outLinks  = mylib.OutLinksComms;
   community;
run;

The resulting output is a partition of the links and nodes of the original graph into communities.

The data table that contains the assignment of nodes to communities, mylib.OutNodesComms, is shown in Output 2.8.1.

Output 2.8.1: Nodes for the Communities of an Undirected Graph

nodecommunity_1
A1
B1
C1
D1
E1
F2
G2
H2
I2
J3
K3
L3


The data table that contains the assignment of links to communities, mylib.OutLinksComms, is shown in Output 2.8.2.

Output 2.8.2: Links for the Communities of an Undirected Graph

fromtocommunity_1
DF.
IJ.
AB1
AC1
AD1
BC1
CD1
CE1
FG2
FH2
FI2
GH2
GI2
JK3
JL3
KL3


The graph seems to have three distinct parts, which are connected by just a few links. The induced subgraphs on these communities are shown in blue in Figure 227 through Figure 229.

Figure 227: Subgraph upper C Superscript 1 Baseline equals StartSet upper A comma upper B comma upper C comma upper D comma upper E EndSet

Subgraph C1 = {A,B,C,D,E}


Figure 228: Subgraph upper C squared equals StartSet upper F comma upper G comma upper H comma upper I EndSet

Subgraph C2 = {F,G,H,I}


Figure 229: Subgraph upper C cubed equals StartSet upper J comma upper K comma upper L EndSet

Subgraph C3 = {J,K,L}


Now, using one call to PROC NETWORK, you can calculate the centrality metrics for all three induced subgraphs by using the BY statement and the links partition defined by the community detection algorithm. In addition, because these subgraphs are completely independent, the processing is done in parallel across machines and threads (depending on your server configuration).

proc network
   links        = mylib.OutLinksComms(where=(community_1 ne .))
   outNodes     = mylib.NodeSetOut;
   centrality
      degree    = unweight
      influence = unweight
      close     = unweight
      between   = unweight
      eigen     = unweight;
   displayout
      ProblemSummary  = ProblemSummary
      SolutionSummary = SolutionSummary;
   by community_1;
run;
%put &_NETWORK_;

Assuming that your grid has a total of at least three cores, all three subgraphs are processed simultaneously with one call to PROC NETWORK. The progress of the procedure is shown in Output 2.8.3.

Output 2.8.3: PROC NETWORK Log: Centrality by Cluster for an Undirected Graph

NOTE: ------------------------------------------------------------------------------------------
NOTE: Running NETWORK.                                                                          
NOTE: ------------------------------------------------------------------------------------------
NOTE: The number of nodes in the input graph is 5.                                              
NOTE: The number of links in the input graph is 6.                                              
NOTE: Processing centrality metrics.                                                            
NOTE: Processing centrality metrics used 0.00 (cpu: 0.00) seconds.                              
NOTE: The above message was for the following BY group:                                         
      community_1=1                                                                             
NOTE: The number of nodes in the input graph is 4.                                              
NOTE: The number of links in the input graph is 5.                                              
NOTE: Processing centrality metrics.                                                            
NOTE: Processing centrality metrics used 0.02 (cpu: 0.00) seconds.                              
NOTE: The above message was for the following BY group:                                         
      community_1=2                                                                             
NOTE: The number of nodes in the input graph is 3.                                              
NOTE: The number of links in the input graph is 3.                                              
NOTE: Processing centrality metrics.                                                            
NOTE: Processing centrality metrics used 0.01 (cpu: 0.00) seconds.                              
NOTE: The above message was for the following BY group:                                         
      community_1=3                                                                             
NOTE: The Cloud Analytic Services server processed the request in 1.066656 seconds.             
NOTE: The data set MYLIB.NODESETOUT has 12 observations and 8 variables.                        
STATUS=OK  PROBLEM_TYPE=CENTRALITY  CPU_TIME=1.72  REAL_TIME=1.07                               


Notice that links that connect different partitions have been removed by using a WHERE clause on the LINKS= option in the PROC NETWORK statement.

The output table mylib.ProblemSummary contains a summary of each induced subgraph that is processed by PROC NETWORK.

Output 2.8.4: Problem Summary by Community

community_1numNodesnumLinksgraphDirection
156Undirected
245Undirected
333Undirected


The output table mylib.SolutionSummary contains a solution summary for the processing on each of the induced subgraphs.

Output 2.8.5: Solution Summary by Community

community_1problemTypestatuscpuTimerealTime
1CentralityOK0.000.00
2CentralityOK0.000.02
3CentralityOK0.000.01


The centrality results (by community) are shown in Output 2.8.6.

Output 2.8.6: Centrality for All Induced Subgraphs

nodecentr_degree_outcentr_eigen_unwtcentr_close_unwtcentr_between_unwtcentr_influence1_unwtcentr_influence2_unwt
A30.898970.800000.083330.61.6
B20.707110.666670.000000.41.4
C41.000001.000000.583330.81.6
D20.707110.666670.000000.41.4
E10.372360.571430.000000.20.8

nodecentr_degree_outcentr_eigen_unwtcentr_close_unwtcentr_between_unwtcentr_influence1_unwtcentr_influence2_unwt
F31.000001.000.166670.751.75
G31.000001.000.166670.751.75
H20.780780.750.000000.501.50
I20.780780.750.000000.501.50

nodecentr_degree_outcentr_eigen_unwtcentr_close_unwtcentr_between_unwtcentr_influence1_unwtcentr_influence2_unwt
J21100.666671.33333
K21100.666671.33333
L21100.666671.33333


Last updated: August 07, 2026