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-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 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
  • 1029 views
  • 5 likes
  • 4 in conversation