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

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
| node | community_1 |
|---|---|
| A | 1 |
| B | 1 |
| C | 1 |
| D | 1 |
| E | 1 |
| F | 2 |
| G | 2 |
| H | 2 |
| I | 2 |
| J | 3 |
| K | 3 |
| L | 3 |
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
| from | to | community_1 |
|---|---|---|
| D | F | . |
| I | J | . |
| A | B | 1 |
| A | C | 1 |
| A | D | 1 |
| B | C | 1 |
| C | D | 1 |
| C | E | 1 |
| F | G | 2 |
| F | H | 2 |
| F | I | 2 |
| G | H | 2 |
| G | I | 2 |
| J | K | 3 |
| J | L | 3 |
| K | L | 3 |
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.
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_1 | numNodes | numLinks | graphDirection |
|---|---|---|---|
| 1 | 5 | 6 | Undirected |
| 2 | 4 | 5 | Undirected |
| 3 | 3 | 3 | Undirected |
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_1 | problemType | status | cpuTime | realTime |
|---|---|---|---|---|
| 1 | Centrality | OK | 0.00 | 0.00 |
| 2 | Centrality | OK | 0.00 | 0.02 |
| 3 | Centrality | OK | 0.00 | 0.01 |
The centrality results (by community) are shown in Output 2.8.6.
Output 2.8.6: Centrality for All Induced Subgraphs
| node | centr_degree_out | centr_eigen_unwt | centr_close_unwt | centr_between_unwt | centr_influence1_unwt | centr_influence2_unwt |
|---|---|---|---|---|---|---|
| A | 3 | 0.89897 | 0.80000 | 0.08333 | 0.6 | 1.6 |
| B | 2 | 0.70711 | 0.66667 | 0.00000 | 0.4 | 1.4 |
| C | 4 | 1.00000 | 1.00000 | 0.58333 | 0.8 | 1.6 |
| D | 2 | 0.70711 | 0.66667 | 0.00000 | 0.4 | 1.4 |
| E | 1 | 0.37236 | 0.57143 | 0.00000 | 0.2 | 0.8 |
| node | centr_degree_out | centr_eigen_unwt | centr_close_unwt | centr_between_unwt | centr_influence1_unwt | centr_influence2_unwt |
|---|---|---|---|---|---|---|
| F | 3 | 1.00000 | 1.00 | 0.16667 | 0.75 | 1.75 |
| G | 3 | 1.00000 | 1.00 | 0.16667 | 0.75 | 1.75 |
| H | 2 | 0.78078 | 0.75 | 0.00000 | 0.50 | 1.50 |
| I | 2 | 0.78078 | 0.75 | 0.00000 | 0.50 | 1.50 |
| node | centr_degree_out | centr_eigen_unwt | centr_close_unwt | centr_between_unwt | centr_influence1_unwt | centr_influence2_unwt |
|---|---|---|---|---|---|---|
| J | 2 | 1 | 1 | 0 | 0.66667 | 1.33333 |
| K | 2 | 1 | 1 | 0 | 0.66667 | 1.33333 |
| L | 2 | 1 | 1 | 0 | 0.66667 | 1.33333 |


