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;
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!
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.