Help using Base SAS procedures

need a help to read the table records with duplicates

Reply
New Contributor
Posts: 3

need a help to read the table records with duplicates

hi,

 

read the table if we have the duplicates it should write to the separate dataset and without duplicates to other dataset.please help

Frequent Contributor
Posts: 108

Re: need a help to read the table records with duplicates

This can be done in lots of different ways ...Pls specify what you are looking for .
New Contributor
Posts: 3

Re: need a help to read the table records with duplicates

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. 

 

Valued Guide
Posts: 858

Re: need a help to read the table records with duplicates

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;

Super User
Super User
Posts: 7,392

Re: need a help to read the table records with duplicates

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;

Super Contributor
Posts: 275

Re: need a help to read the table records with duplicates


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;

 

Super User
Posts: 5,076

Re: need a help to read the table records with duplicates

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?

New Contributor
Posts: 3

Re: need a help to read the table records with duplicates

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.
Valued Guide
Posts: 858

Re: need a help to read the table records with duplicates

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.

Ask a Question
Discussion stats
  • 8 replies
  • 369 views
  • 0 likes
  • 6 in conversation