BookmarkSubscribeRSS Feed
rawindar
Calcite | Level 5

i have dataset A with some repeated observations in ACCOUNTNO variable,dataset B also have duplicate observations ,boath datasets having common variable ACCOUNTNO .How can we merge boath datasets by removing duplicates using merge.

7 REPLIES 7
Ksharp
Super User

If you do not want duplicated accountno during merge, proc sort data=have nodupkey;by accountno;run;

or SQL can keep the accountno unique.

Ksharp

rawindar
Calcite | Level 5

thank..u but i want to write it using MERGE .It is better if you provide ans using MERGE .I have faced this ques in an interview.

rawindar
Calcite | Level 5

thank ...u

Patrick
Opal | Level 21

....

merge a b;

by accountno;

if first.accountno;

....

I would assume in an interview situation you should also ask what's meant by duplicates - duplicate keys or duplicate rows (=all variables having the same values).

Above code snippet is for duplicate rows.

rawindar
Calcite | Level 5

Thanks  for ur reply.yes i asked duplicates occured in data values of Accountno variable

Tom
Super User Tom
Super User

If you are asked that question in an interview (or real life) you need to respond with some questions so you can figure out what they want.

Do they want to match every obversation in A with every observation in B that has the same account number?

What about account numbers that only occur in A or B?

Do they want to pair them up in order within the account numbers? 

What happens if there are not the same number of observations in both A and B for a particular account number.

Once you have the answers to those questions you can begin to build a strategy for "merging" them.

But in general SQL will be much more useful language for coding that than a data step using the MERGE statement.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 859 views
  • 3 likes
  • 5 in conversation