BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
KarenGeurts
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
7 REPLIES 7
Reeza
Super User

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.

KarenGeurts
Calcite | Level 5

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

Reeza
Super User

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

PGStats
Opal | Level 21

This can be done with my SubGraphs macro. See

 

How to find all connected components in a graph

 

PG

PG
KarenGeurts
Calcite | Level 5

It works wonderfully.

Thank you very much

Karen

Reeza
Super User

@ChrisHemedinger

Where would this document now exist?

 

ChrisHemedinger
Community Manager

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

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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