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.
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.