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