BookmarkSubscribeRSS Feed
mlogan
Lapis Lazuli | Level 10

Hi All,

Can someone tell me how to get the duplicate value within by group. Thanks,

 

ID     Subject

100   English

100   Math

100   Biology

111   English

111   Biology

111   Math

111   Math

111  Biology

112  Chemistry

112   English

112   Physics

112   Math

112   English

 

Outpu table will be:

 

ID     Subject

111   Biology

111   Biology

112   English

112   English

4 REPLIES 4
Reeza
Super User
proc sort data=have;
by id subject;
run;

data dups;
set have;
by id subject;
if not (first.subject and last.subject) then output;
run;
SAS_inquisitive
Lapis Lazuli | Level 10
proc sort data=have nodupkey dupout=dups;
  by id subject;
run;
Reeza
Super User

Proc Sort identifies one of the duplicate records not both.  

If you want to identify both using PROC SORT use the NOUNIQUEKEY option instead.

 

proc sort data=have nouniquekey out=want;
  by id subject;
run;

proc print data=want;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Or:

proc sort data=have out=nondups dupout=want nodupkey;
  by id subject;
run;

This will give you a dataset want which has all the duplicate values, you can sort it again nodupkey to get distinct values, also you do:

proc sql;
create table WANT as
select distinct ID,SUBJECT
from HAVE
group by ID,SUBJECT
having count(*) > 1;
quit;

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
  • 4 replies
  • 993 views
  • 0 likes
  • 4 in conversation