11-01-2016 11:48 AM
I am trying to find duplicates and only keep the unique obs (doesn't matter if it is the first or the last record). I used the variable called Plural to identify them and Plural has three categories (1, 2, and 3). Plural=1 means there are no duplicates, Plural=2 means there are two records (per person) and Plural=3 means there are three records (per person). I tried:
where plural >1;
and obviously, the dataset nodup only has the one w/ Plural>1. Is there any way I can keep every record in the dataset (plural=1, 2, or 3), but remove duplicates if Plural>1?
11-01-2016 12:15 PM
Please be more specific about what you want to remove. When you say remove duplicates that implies remove duplicate records and yet you say you want to keep all records. what do you want to remove if not the record ?.
11-01-2016 12:34 PM
I want to remove duplicate records (e.g. where plural >1), but I want all unique records (including where plural=1) in the dataset not just the ones with multiple records (plural>1). I hope this makes sense.
11-01-2016 02:45 PM
Thank you for your comment- Okay so I tweaked what you suggested and tried the code below: Basically, I sorted by enough keys to get a unique combination per row; then use a data step to number each row as I want.
proc sort data=old; by id dob border; run;
by id dob border;
if first.dob then kid= 1;
else kid= 1+kid; run;
Not sure what I am missing here, but all the observations in my dataset have kid=1. In theory, they should be numbered 1-2-3 and then next record to a different person would be numbered 1. Any suggestion?
11-01-2016 04:23 PM
It's looking like this statement needs to change:
if first.dob then kid=1;
Probably, it should become (with no other changes required):
if first.id then kid=1;
Basically, you are numbering the records for each ID/DOB combination. Your results indicate there is only one observation for each group. The change will number the records for each ID. Hopefully, that's what you are hoping to do.