BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Siva_Harish
Obsidian | Level 7

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
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;
    

 

 

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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;
    

 

 

--
Paige Miller
Reeza
Super User
Self join - you can join a table with itself.

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 620 views
  • 0 likes
  • 4 in conversation