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

Hi admin and others,

 

I have the data:

ID   EventDate             Value    

1     17/07/1999       a 

1     08/8/1999       b

1    20/11/1999       c

1    04/06/2003        d

1    11/05/2005        e

1    08/09/2005  ..

1    02/11/2005 --

1    17/2/2006  --

1    28/09/2006--

I want to delete for the same id during the three months before or after Eventdate. So if the 17/07/1999 then next date is 20/11/1999, delete 08/10/1999 because intck ("month", 17/07/1999, 08/08/1999)< 3 months. But if 08/08/1999 deleted, then I will check 17/07/1999 and 20/11/199, the distance is more than 3 months then I keep it. 

The I tried to combine all data by itself by id, then if intck >3 then delete then I have two (17/7/1999 and 20/11/1999) ( 08/08/1999 and 20/11/1999) and I have no idea to delete 08/08. If first.date ... cannot work for this case and I cannot keep the last date if use intck.

Please help and advise.

 

Thank you so much,

Ha

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
 

data have;
Input ID   EventDate   :ddmmyy10.          Value    $;
format EventDate   ddmmyy10. ;
cards;
1     17/07/1999       a 
1     08/8/1999       b
1    20/11/1999       c
1    04/06/2003        d
1    11/05/2005        e
;


data want;
set have;
by id;
retain _d;
if first.id then do;output; _d=eventdate;end;
else if intck('mon',_d,eventdate)>3 then do;output;_d=eventdate;end;
drop _d;
run;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Are the comparisons always to the first date (17/07/1999) or to the previous non-deleted date?

--
Paige Miller
yotsuba88
Quartz | Level 8
Hi Paige,

Thank you for your question. I want to compare with the previous non-deleted date.
novinosrin
Tourmaline | Level 20

Hello @yotsuba88   Please post a sample of your expected OUTPUT(WANT) for the input sample(HAVE) with your explanation. Thank you!

novinosrin
Tourmaline | Level 20
 

data have;
Input ID   EventDate   :ddmmyy10.          Value    $;
format EventDate   ddmmyy10. ;
cards;
1     17/07/1999       a 
1     08/8/1999       b
1    20/11/1999       c
1    04/06/2003        d
1    11/05/2005        e
;


data want;
set have;
by id;
retain _d;
if first.id then do;output; _d=eventdate;end;
else if intck('mon',_d,eventdate)>3 then do;output;_d=eventdate;end;
drop _d;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 4 replies
  • 1255 views
  • 3 likes
  • 3 in conversation