BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mcdj
Obsidian | Level 7

Hi there,I have longitudinal data in long format. each individual (part of a couple) is supposed to have a single row per visit. there are some, like below, that have 2 entries for an individual on the same date. I need to find out which IDs and for which visitdates there are multiple rows/entries. Help? Thanks!

 

Obs id htid womanage manage cjbase visitdate linked inflam_3mo_female
1244 5538M 5538 22 35 +- 05NOV2003 1 .
1245 5538F 5538 22 35 +- 05NOV2003 1 1
1246 5538F 5538 22 35 +- 05NOV2003 1
1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

If you wish to output all observations in a duplicate situation, you can use SQL as well (untested):

 

proc sql;
   create table want as
      select *
      from have
      group by id, visitdate
      having count(*) > 1
   ;
quit,

If you just wish to output the duplicate observation(s), use proc sort with the dupout= option.

 

Data never sleeps

View solution in original post

4 REPLIES 4
mohamed_zaki
Barite | Level 11
proc sort data=have out=havesorted;
by id visitdate;
run;
data want ;
set havesorted ;
by id visitdate;
if not (first.visitdate and last.visitdate) then output;
run;
LinusH
Tourmaline | Level 20

If you wish to output all observations in a duplicate situation, you can use SQL as well (untested):

 

proc sql;
   create table want as
      select *
      from have
      group by id, visitdate
      having count(*) > 1
   ;
quit,

If you just wish to output the duplicate observation(s), use proc sort with the dupout= option.

 

Data never sleeps
ballardw
Super User

And yet another possibility

proc freq data=have noprint;

   tables Id*visitdate/list out=dups (where=(count>1));

run;

 

mcdj
Obsidian | Level 7

thanks, worked perfectly!

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1486 views
  • 5 likes
  • 4 in conversation