Help using Base SAS procedures

how can i merge

Reply
Contributor
Posts: 70

how can i merge

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.

Super User
Posts: 10,020

how can i merge

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

Contributor
Posts: 70

how can i merge

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.

PROC Star
Posts: 7,468

how can i merge

Contributor
Posts: 70

how can i merge

thank ...u

Respected Advisor
Posts: 4,173

Re: how can i merge

....

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.

Contributor
Posts: 70

how can i merge

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

Super User
Super User
Posts: 7,039

how can i merge

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.

Ask a Question
Discussion stats
  • 7 replies
  • 218 views
  • 3 likes
  • 5 in conversation