Hi,
I have to compare surgery date and lab date
surgery date stays same whereas lab_date changes and the dates are datetimes
we have to check if lab date is +/- 2 weeks from surgery date and keep only those and discard others
Surgery date lab_date
28jun2011:9:30 09jul2011:10:00----------keep
28jun2011:9:30 16jul2011:12:00---------discard(lab date more than 2 weeks from surg date)
28jun2011:9:30 08jul2011:09:00-------keep
Thanks
please try,
data have;
input date1 : datetime18. date2 : datetime18.;
format date1 date2 datetime18.;
if (datepart(date2)-datepart(date1))/7 >2 then delete;
cards;
28jun2011:9:30 09jul2011:10:00
28jun2011:9:30 16jul2011:12:00
28jun2011:9:30 08jul2011:09:00
;
run;
Thanks,
jagadish
Hi Jagadish,
But here you're not consider time part.I think you should time part also.
Regards,
Ramesh
I probably would use intck() instead of an expression like "(datepart(date2)-datepart(date1))/7 >2"
when i try to use intck function, the result in week is a integer value. so we are unable to check if the week is 2 or more than 2. as per the data provided the second record is more than 2 weeks, however with intck it is 2.
data have;
input date1 : datetime18. date2 : datetime18.;
format date1 date2 datetime18.;
value1=(datepart(date2)-datepart(date1))/7;
value=intck('week', datepart(date1), datepart(date2));
cards;
28jun2011:9:30 09jul2011:10:00
28jun2011:9:30 16jul2011:12:00
28jun2011:9:30 08jul2011:09:00
;
run;
Please check the difference between value1 and value variables. is there any way to avoid it with intck. please suggest.
With datetime values I would use the datetime intervals with intck().
if intck('dtday', date1, date2) > 13 then delete;
Thanks Patrick , indeed a good way
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.