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 |
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.
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;
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.
And yet another possibility
proc freq data=have noprint;
tables Id*visitdate/list out=dups (where=(count>1));
run;
thanks, worked perfectly!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.