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

Hi there, I am trying to flag duplicate values in my data set.

I have this:

ID

BirthDate

1

12/07/95

1

12/07/95

1

12/07/95

2

12/24/99

2

12/24/99

3

07/26/98

4

09/29/82

 

and I want this:

ID

BirthDate

Recurrent

1

12/07/95

1

1

12/07/95

2

1

12/07/95

3

2

12/24/99

1

2

12/24/99

2

3

07/26/98

1

4

09/29/82

1

 

I found the following code in the communities forum but I cannot seem to make it work... Any help is appreciated.

 

data want;
count=0;
do until (last.BirthDate);
set have;
by ID BirthDate;
if first.BirthDate then count + 1;
end;
if count > 1 then Recurrent=1; else Recurrent=0;
do until (last.BirthDate);
set temp_names;
by ID BirthDate;
output;
end;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
input (ID	BirthDate) (:$15.);
cards;
1	12/7/1995
1	12/7/1995
1	12/7/1995
2	12/24/1999
2	12/24/1999
3	7/26/1998
4	9/29/1982
;

data want;
 set have;
 by id birthdate;
 if first.BirthDate then Recurrent=1;
 else Recurrent+1;
run;

 

ID BirthDate Recurrent
1 12/7/1995 1
1 12/7/1995 2
1 12/7/1995 3
2 12/24/1999 1
2 12/24/1999 2
3 7/26/1998 1
4 9/29/1982 1

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
data have;
input (ID	BirthDate) (:$15.);
cards;
1	12/7/1995
1	12/7/1995
1	12/7/1995
2	12/24/1999
2	12/24/1999
3	7/26/1998
4	9/29/1982
;

data want;
 set have;
 by id birthdate;
 if first.BirthDate then Recurrent=1;
 else Recurrent+1;
run;

 

ID BirthDate Recurrent
1 12/7/1995 1
1 12/7/1995 2
1 12/7/1995 3
2 12/24/1999 1
2 12/24/1999 2
3 7/26/1998 1
4 9/29/1982 1
advmsj
Obsidian | Level 7

Thank you so much. I did not realize it was this simple! 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 489 views
  • 1 like
  • 2 in conversation