hi,
read the table if we have the duplicates it should write to the separate dataset and without duplicates to other dataset.please help
hi,
thanks for your reply.
The table has duplicates,from that table i have read the records,the records which have duplictes should go one dataset and the records without duplicates should go to other data set.
There's a few ways to do this, it's best to give an example of the data you have and what you want to see. Here's one solution:
data have;
input variable;
cards;
1
1
1
2
3
4
5
;
data dup nodup;
do until(last.variable);
set have;
by variable;
count + 1;
if first.variable then count = 1;
if count > 1 then dup = 'Y';
end;
do until(last.variable);
set have;
by variable;
if dup = 'Y' then output dup;
else output nodup;
end;
run;
Or, to save yourself all that typing, you could do:
proc sort data=have out=uniques dupout=dups nodupkey;
by <id variables>;
run;
And then if you want only those singles (as wasn't clear from the original post):
proc sql;
create table WANT as
select * from UNIQUES
where <id variables> not in (select <id vars> from DUPS);
quit;
It is easy to do with proc sort.
If you want to keep one record from duplicate records, you could use nodupkey,
out dataset is Non_dup,remaining duplicate records go to up.
If you want to keep all unique record, use nouniqueley,all records go to uniqueout, othwise go to out.
data have;
input x $ y;
cards;
A 1
A 2
B 1
C 3
C 3
D 3
E 9
;
proc sort data=have out=Non_dup dupout=dup nodupkey ;
by x;
run;
proc sort data=have uniqueout=Unique out=all_dup nouniquekey;
by x;
run;
Here are the pieces that you didn't tell us:
(a) What constitutes a duplicate? Is just one variable the same, or are all variables the same?
(b) If there are duplicates, should all of them go into the same data set? Or should the first one go into a separate data set and any additional duplicates go into a different data set?
In that case I think you want to use the solution I provided earlier. Run that with a subset and see if you get the desired results.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.