Hi ,
How to get same id presented same topic_id within within (less than) 45 days.
Can anyone help me on this?
| ID | EVENT_START_DATE | TOPIC_ID |
| 4 | 18Sep2019 14:30:00 | 427EP1905697-01 |
| 4 | 18Dec2019 15:15:00 | 427EP1905697-01 |
| 4 | 21Feb2020 18:30:00 | 427EP1905697-01 |
| 4 | 18Sep2019 14:30:00 | 427ES18PR07337-01 |
| 4 | 18Dec2019 15:15:00 | 427ES18PR07337-01 |
| 4 | 21Feb2020 18:30:00 | 427ES18PR07337-01 |
| 4 | 18Sep2019 14:30:00 | IMSES18PR03522-01 |
| 4 | 18Dec2019 15:15:00 | IMSES18PR03522-01 |
| 4 | 21Feb2020 18:30:00 | IMSES18PR03522-01 |
| 6 | 12Sep2019 17:30:00 | 427EP1905697-01 |
| 6 | 18Sep2019 14:30:00 | 427EP1905697-01 |
| 6 | 18Dec2019 15:15:00 | 427EP1905697-01 |
| 6 | 12Sep2019 17:30:00 | 427ES18PR07337-01 |
| 6 | 18Sep2019 14:30:00 | 427ES18PR07337-01 |
| 6 | 18Dec2019 15:15:00 | 427ES18PR07337-01 |
| 6 | 12Sep2019 17:30:00 | IMSES18PR03522-01 |
| 6 | 18Sep2019 14:30:00 | IMSES18PR03522-01 |
| 6 | 18Dec2019 15:15:00 | IMSES18PR03522-01 |
Assuming your EVENT_START_DATE is truly numeric date/time values in SAS, and assuming your data is properly sorted by ID and TOPIC_ID, you can use the DIF Function.
data want;
set have;
by id topic_id;
delta=dif(event_start_date);
if not first.topic_id and delta<45*86400 then flag='Less than 45 days';
drop delta;
run;
Apply the same basic technique I showed you here.
Assuming your EVENT_START_DATE is truly numeric date/time values in SAS, and assuming your data is properly sorted by ID and TOPIC_ID, you can use the DIF Function.
data want;
set have;
by id topic_id;
delta=dif(event_start_date);
if not first.topic_id and delta<45*86400 then flag='Less than 45 days';
drop delta;
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!
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.