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 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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