DATA Step, Macro, Functions and more

How to merge multiple datasets with no duplicates?

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

How to merge multiple datasets with no duplicates?

Hi,

 

Let's say that I have 3 datasets:

 

datasets.PNG

 

 

 

 

 

 

 

I want to merge those 3 datasets in a way that the result will look like this

 

dataset_al.PNG

 

 

 

 

 

 

 

 

 

But using the code below

data dataset_wrong;
      merge dataset_a dataset_b dataset_c;
      by A;
run;

the result is

 

 

dataset_wrong.PNG

 

 

 

 

 

 

 

 

What is the right code to produce the result I want.

 

Thank you in advance.


Accepted Solutions
Solution
3 weeks ago
Super User
Posts: 7,795

Re: How to merge multiple datasets with no duplicates?

try the following:

data dataset_wrong;
if _n_ = 0 then merge dataset_a dataset_b dataset_c;
/* this does nothing, but is needed to make the following work */
call missing(of _all_);
merge
  dataset_a
  dataset_b
  dataset_c
;
by A;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
3 weeks ago
Super User
Posts: 7,795

Re: How to merge multiple datasets with no duplicates?

try the following:

data dataset_wrong;
if _n_ = 0 then merge dataset_a dataset_b dataset_c;
/* this does nothing, but is needed to make the following work */
call missing(of _all_);
merge
  dataset_a
  dataset_b
  dataset_c
;
by A;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 2

Re: How to merge multiple datasets with no duplicates?

Posted in reply to KurtBremser
Thank you that seems to work.
☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 87 views
  • 3 likes
  • 2 in conversation