BookmarkSubscribeRSS Feed
user24
Obsidian | Level 7

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.

 

3 REPLIES 3
art297
Opal | Level 21

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

LinusH
Tourmaline | Level 20

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

Data never sleeps
Ksharp
Super User

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1103 views
  • 3 likes
  • 4 in conversation