DATA Step, Macro, Functions and more

How to create a group-ID for interlinked ID numbers?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

How to create a group-ID for interlinked ID numbers?

I have a dataset with 2 columns of ID numbers (id1 id2). Each row establishes a link between 2 ID numbers There are several many-to-many links, and some ID numbers appear in both columns. I want to create a "group-ID" for all IDs which are interlinked with each other. How can I do this?

In the example below, I want to create 2 group IDs: one for ID numbers a b c d, and another for ID numbers e f.

data have;

input (id1 id2) (:$1.);

cards;

a b

a c

b d

e f

;

Thanks for your help.

Karen


Accepted Solutions
Solution
‎03-12-2013 12:02 PM
Esteemed Advisor
Posts: 5,523

Re: How to create a group-ID for interlinked ID numbers?

[ Edited ]
Posted in reply to KarenGeurts

This can be done with my SubGraphs macro. See

 

How to find all connected components in a graph

 

PG

PG

View solution in original post


All Replies
Super User
Posts: 23,683

Re: How to create a group-ID for interlinked ID numbers?

Posted in reply to KarenGeurts

If you have SAS/OR licensed then look at PROC BOM.

If not, there's a good solution posted on here earlier that some searching may help find.

Occasional Contributor
Posts: 6

Re: How to create a group-ID for interlinked ID numbers?

Thank for your answer, but I do not have SAS/OR.

I used the macro SubGraphs as suggested by PG, which works very well

Karen

Super User
Posts: 23,683

Re: How to create a group-ID for interlinked ID numbers?

Posted in reply to KarenGeurts

I don't have SAS/OR anymore either, so I'm glad to see PG's macro as well!

Solution
‎03-12-2013 12:02 PM
Esteemed Advisor
Posts: 5,523

Re: How to create a group-ID for interlinked ID numbers?

[ Edited ]
Posted in reply to KarenGeurts

This can be done with my SubGraphs macro. See

 

How to find all connected components in a graph

 

PG

PG
Occasional Contributor
Posts: 6

Re: How to create a group-ID for interlinked ID numbers?

It works wonderfully.

Thank you very much

Karen

Super User
Posts: 23,683

Re: How to create a group-ID for interlinked ID numbers?

@ChrisHemedinger

Where would this document now exist?

 

Community Manager
Posts: 3,424

Re: How to create a group-ID for interlinked ID numbers?

@Reeza - I fixed the link to point to the proper article.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 330 views
  • 2 likes
  • 4 in conversation