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
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;
Are the comparisons always to the first date (17/07/1999) or to the previous non-deleted date?
Hello @yotsuba88 Please post a sample of your expected OUTPUT(WANT) for the input sample(HAVE) with your explanation. Thank you!
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;
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!
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.