0

I'm working on migrating some SAS programs into R, and I'm having a difficult time figuring out the best way to accomplish this seemingly simple bit of logic.

DATA HAVE;  
MERGE HAVE1  HAVE2;
BY ID;
RUN;    

Example for Match merge is,

HAVE1:

ID  A   B   
10  1   2   
20  3   4   
30  5   6   

HAVE2:

ID  C       
10  0       
30  1       
40  1       

HAVE:

ID  A   B   C
10  1   2   0
20  3   4   .
30  5   6   1
40  .   .   1
MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • With base R this is `merge(HAVE1, HAVE2)` or with dplyr `inner_join(HAVE1, HAVE2)`. R will automatically join by ID since that's the only column name common to both data frames. – MrFlick May 13 '22 at 20:01
  • 2
    I think you want `merge(HAVE1, HAVE2, all = TRUE)` or `outer_join(HAVE1, HAVE2)` to get the desired output. – Jon Spring May 13 '22 at 20:14
  • 1
    Since you are not doing a many to many join the linked question will work. But if you were doing a many to many join then the SAS merge code will behave differently than the default joins in R. – Tom May 14 '22 at 15:48
  • Thanks. All the above comments were helpful – David Billa May 22 '22 at 16:07

0 Answers0