BookmarkSubscribeRSS Feed
mar0000
Obsidian | Level 7
data have;
input Patient_ID $   date  Date9.     Activity $ ;
format date date9.;
datalines;
1234 20FEB2020 Football 
1234 20FEB2020 Basketball 
1234 25FEB2020 Ski 
1234 07SEP2020 Baseball 

 How would I create a variable that says 'Y' to the first line that has patient 1234 playing football, and 'N' to person 1234 playing basketball because they are playing on the same day. I want to say 'Y' to person 1234 on 25FEB2020 and 'Y' for patient 1234 on 07SEP2020. 

 

1 REPLY 1
andreas_lds
Jade | Level 19

So you want to flag the first observation for each Patient_ID and date with "Y" and any other observation with "N"? Assuming that the data is sorted by Patient_ID and date:

data want;
	set have;
	by Patient_ID date;
	
	length status $ 1;

	status = ifc(first.date, 'Y', 'N');
run;

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1 reply
  • 355 views
  • 1 like
  • 2 in conversation