BookmarkSubscribeRSS Feed
JLang055
Fluorite | Level 6

Hello. I have a patient dataset with observations by participant. I want to flag participants with multiple observations in the dataset. See below for an example.

FIDFlag (want)
11
10
20
30
41
40
40
50
3 REPLIES 3
JLang055
Fluorite | Level 6

Thanks @Kurt_Bremser. It seems that your code flagged the first observation for every participant. Is there a way to change the code so that it only flags those with multiple observations. If a participant has only one observation I dont want them flagged. 

Kurt_Bremser
Super User

Simply cannot be with the data you posted and my code:

data have;
input fid;
datalines;
1
1
2
3
4
4
4
5
;

data want;
set have;
by fid;
flag = (first.fid and not last.fid);
run;

proc print data=want noobs;
run;

Result:

id	flag
1	1
1	0
2	0
3	0
4	1
4	0
4	0
5	0

Matches exactly with your expected result from your initial post:

FID Flag (want)
1 1
1 0
2 0
3 0
4 1
4 0
4 0
5 0

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 547 views
  • 5 likes
  • 2 in conversation