I want to be able to flag those individuals who have multiple encounters and a previous encounter falls within a certain group, but only if it happens within a specified time frame (I am able to calculate the time, I'm just trying to illustrate the relationship.)
Here is an example. For ID 1234 there are two encounters, where the first is a type 1 and the second encounter happened at day 7. How can I loop the second encounter back to the previous (7-Jul-2020) encounter to confirm that encounter is a type 1 and therefore should fall into the bucket?
I don't care about ID 5656 because none of them fall into type 1.
| ID | Date | Group | delta | Bucket |
| 1234 | 7-Jul-20 | 1 | ||
| 1234 | 14-Jul-20 | 0 | 7 | 1 |
| 5656 | 7-Jul-20 | 0 | ||
| 5656 | 14-Jul-20 | 0 | 7 | |
| 8879 | 7-Jul-20 | 0 | ||
| 8879 | 14-Jul-20 | 1 | 7 | |
| 8879 | 21-Jul-20 | 0 | 7 | 1 |
Please post data in usable form using the variable names you are using in the description.
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.