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! 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 738 views
  • 1 like
  • 2 in conversation