subgraph

Returns a subgraph of g, as determined by the nodes_subset and edges_subset parameter values.

sasviya.network.utils.utils.subgraph(g, nodes_subset=None, edges_subset=None, immutable=None, *, data=True, induced=False)

Parameters

g : SAS graph object

Specifies the input graph to assess.

nodes_subset : iterable of nodes or None, optional

Specifies the subset of nodes to include in the subgraph. The default is None.

edges_subset : iterable of edges or None

Specifies the subset of edges in the form of two-tuples [(u,v)] or three-tuples [(u,v,edge_key)]; for example, [(1,2),(3,4)] or [(1,2,0),(1,2,1),(2,1,0)]. The default is None.

immutable : bool or None, optional

Specifies whether or not to return an immutable copy. The default is None, which means that the mutability matches the input graph.

data : bool, optional

Specifies whether or not to retain attributes. The default is True, meaning that the node and edge attributes of the graph are retained.

induced : bool, optional

Specifies whether or not to call the induced_subgraph function and to add nodes that are listed in the nodes_subset parameter as well as the edges incident on those nodes. The default is False, which means that only the list of nodes is added to the output graph.

Returns

SAS graph object

Returns a subgraph of the graph, as determined by the different values of the nodes_subset and edges_subset parameters. When the nodes_subset parameter is specified but the edges_subset parameter value is None: If the induced parameter value is True, the output graph contains all nodes that are listed in the nodes_subset parameter and all edges incident on those nodes. If the induced parameter value is False, the output graph contains only the nodes that are listed in the nodes_subset parameter; no edges are added. When the edges_subset parameter is specified but the nodes_subset parameter value is None: The output graph contains all edges that are listed in the edges_subset parameter and all nodes (from,to) that are listed in the edges_subset parameter. When both the edges_subset and nodes_subset parameters are specified: If the induced parameter value is True, the output graph includes all nodes that are listed in either the edges_subset or nodes_subset parameter as well as all edges incident to those nodes. If the induced parameter value is False, the output graph contains any node that is listed in the nodes_subset or edges_subset parameter, but it contains only edges that are listed in the edges_subset parameter.

Last updated: July 28, 2026