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.
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
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.
Take a look at: http://www2.sas.com/proceedings/forum2008/081-2008.pdf
thank ...u
....
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.
Thanks for ur reply.yes i asked duplicates occured in data values of Accountno variable
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.
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.
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.