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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 883 views
  • 3 likes
  • 5 in conversation