DATA Step, Macro, Functions and more

Remove if the variable doesn't have duplicate

Reply
Contributor
Posts: 33

Remove if the variable doesn't have duplicate

[ Edited ]

i want to remove if the id has not duplicate, like as below. Thisis table example i have now

 

id          desc                        i

15        W100786                 1

15        03/21/1970              2

20        K64478                   1

20        02/14/1968              2

21         M157842                1

22        W250143                1

22        02/15/2000              2

 

 

i need the table as below:

                  

id          desc                        i

15        W100786                 1

15        03/21/1970               2

20        K64478                   1

20        02/14/1968               2

22        W250143                1

22        02/15/2000               2

 

So i need to remove the id:21, because it doesn't have duplicate.

 

PROC Star
Posts: 7,492

Re: Remove if the variable doesn't have duplicate

[ Edited ]

If you're data is already sorted by ID then a small data step would work:

 

data want;
  set have;
  by ID;
  if not(first.id and last.id);
run;

Art, CEO, AnalystFinder.com

Super User
Posts: 5,441

Re: Remove if the variable doesn't have duplicate

Or, if your data isn't sorted, try SQL GROUP BY, with a HAVING count(*) =2.

Data never sleeps
Super User
Posts: 10,046

Re: Remove if the variable doesn't have duplicate

Or NOUNIQUEKEY.

 

data have;
input id          desc  : $20.                       i;
cards;
15        W100786                 1
15        03/21/1970              2
20        K64478                   1
20        02/14/1968              2
21         M157842                1
22        W250143                1
22        02/15/2000              2
;
run;


proc sort data=have out=want nouniquekey;
by id;
run;
Ask a Question
Discussion stats
  • 3 replies
  • 322 views
  • 3 likes
  • 4 in conversation