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
proc sort data=have;
by name;
run;
data have2;
set have;
by name;
if first.name ne last.name then diff_flag=1;
run;
Which one though? Does it matter? You don't specify.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.