Learning SAS? Welcome to the exclusive online community for all SAS learners.

Converting Many-Many to One-One Merge

Occasional Contributor
Posts: 9

Converting Many-Many to One-One Merge

I need some help in converting a many-many merge to one-one merge logically.

I have a dataset which post-merge is of the type:

A X1

A X2

A X3

B X1

B X2

B X4

C X2


I need the maximum possible combinations of Var1 and Var2. So the output should look like:

A X1

B X4

C X2


Is there any optimum way to do it other than working on a row and checking with all the rows already worked on. The dataset would be quite big, hence need to optimize the code.


Thanks in advance.


Super User
Posts: 6,184

Re: Converting Many-Many to One-One Merge

Posted in reply to gaurav_248

If the observations are in order BY VAR1 VAR2, you can do this easily:


data want;

   set have;

   by var1 var2;

   if last.var1;



In fact, if the observations are in the proper order, that subsetting IF could be added to the DATA step that contains the MERGE statement.

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation