BookmarkSubscribeRSS Feed
Emma2021
Quartz | Level 8
I have 3 variables: name, gender, and age. If name is different I want to identify. How can I do?
Example data input data:

Gender Age Name
F 2 Patsy
F 2 Patsy
F 2 Pat
M 3 Steve

Desired output:
Gender Age Name
F 2 Pat



Thank you.
8 REPLIES 8
maguiremq
SAS Super FREQ
data have;
input gender $1. age 3. name :$7.;
datalines;
F 2 Patsy
F 2 Patsy
F 2 Pat
M 3 Steve
;
run;

proc sort data = have;
	by name;
run;

data want;
	set have;
	by name;
		if first.name then counter = 1;
			else counter + 1;
run;
Obs 	gender 	age 	name 	counter
1 	F 	2 	Pat 	1
2 	F 	2 	Patsy 	1
3 	F 	2 	Patsy 	2
4 	M 	3 	Steve 	1
tarheel13
Rhodochrosite | Level 12
proc sort data=have;
  by name;
run;

data have2;
  set have;
  by name;
  if first.name ne last.name then diff_flag=1;
run;
Ksharp
Super User
How do you know 'Patsy' and 'Pat' are the same person ?
Emma2021
Quartz | Level 8
Thank you.
I would like to identify those cases (the same age and gender and different names).
So the final output can be:
Either this:
F 2 Patsy

Or this:
F 2 Pat


Thank you.
Ksharp
Super User
What if data like this :

F 2 Patsy
F 2 Patsy
F 2 Pat
F 2 Patrick
F 2 Patrick
Emma2021
Quartz | Level 8
Thank you.
Then the output should be one of those 3 names.
tarheel13
Rhodochrosite | Level 12

Which one though? Does it matter? You don't specify. 

Emma2021
Quartz | Level 8
It does not matter which one—thank you so much!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 8 replies
  • 888 views
  • 1 like
  • 4 in conversation