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

Hi folks,

 

I have a data set on emergency healthcare use by children so one id can have multiple admission dates to emergency wards. My problem is same id with same admission date more than once.

 

So, I want to find out duplicates based on two variables; 'id' and 'admissiondate' and create a data set without duplicates but before I create a data set without duplicates I need to know how many duplicate entries I have in the data set for verification purposes.

 

Thanks

S

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @sks521 

 

You can use a PROC SORT to do that with the NODUPKEY option

The DUPOUT = option will output a dataset 'want' with the duplicate records base on the key 'id admissiondate' specified in the BY statement.

The OUT = option will output a dataset 'duplicates' with no duplicate records

proc sort data=have out = want dupout = duplicates nodupkey;
	by id admissiondate;
run;

 

View solution in original post

4 REPLIES 4
ed_sas_member
Meteorite | Level 14

Hi @sks521 

 

You can use a PROC SORT to do that with the NODUPKEY option

The DUPOUT = option will output a dataset 'want' with the duplicate records base on the key 'id admissiondate' specified in the BY statement.

The OUT = option will output a dataset 'duplicates' with no duplicate records

proc sort data=have out = want dupout = duplicates nodupkey;
	by id admissiondate;
run;

 

rohitdante16
Fluorite | Level 6

Best Method now is:

proc sort data=ds1 out =ds2 dupout = dup nodupkey;
by id admissiondate;
run;

 

s_lassen
Meteorite | Level 14

Sort your data by ID and AdmissionDate, and then use a data step:

data want;
  do NDups=0 by 1 until(last.AdmissionDate);
    set have;
    by ID AdmissionDate;
    end;
run;

The NDups variable should the contain the number of duplicates for each by group.

ballardw
Super User

@sks521 wrote:

Hi folks,

 

I have a data set on emergency healthcare use by children so one id can have multiple admission dates to emergency wards. My problem is same id with same admission date more than once.

 

So, I want to find out duplicates based on two variables; 'id' and 'admissiondate' and create a data set without duplicates but before I create a data set without duplicates I need to know how many duplicate entries I have in the data set for verification purposes.

 

Thanks

S


This will create a data set that has the id and admiisiondate with a count of how many duplicates when there are duplicates.

 

proc freq data=have noprint;
   tables id*admissiondate /out=work.counts (drop=percent where=(count>1)) ;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 567 views
  • 3 likes
  • 5 in conversation