SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Finding redundant entries for same ID and date

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Finding redundant entries for same ID and date

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

Accepted Solutions
Solution
‎02-11-2016 09:51 AM
Super User
Posts: 5,426

Re: Finding redundant entries for same ID and date

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


All Replies
Super Contributor
Posts: 490

Re: Finding redundant entries for same ID and date

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;
Solution
‎02-11-2016 09:51 AM
Super User
Posts: 5,426

Re: Finding redundant entries for same ID and date

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
Super User
Posts: 11,343

Re: Finding redundant entries for same ID and date

And yet another possibility

proc freq data=have noprint;

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

run;

 

Occasional Contributor
Posts: 17

Re: Finding redundant entries for same ID and date

thanks, worked perfectly!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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