在sas数据集中查找指定日期的最近日期?

时间:2013-05-20 00:43:03

标签: sas

根据数据,任何人都可以帮助我 - 制作一个包含

的程序

test_date最接近delivery_date。

delivery_date 11/16/2011

test_date 21 / nov / 2011 10 / nov / 2011 5 / oct / 2010

提前致谢

2 个答案:

答案 0 :(得分:0)

如果没有更多信息,无法正确回答,但如果每个日期有两个数据集和一行,以及实际日期变量,则解决方案如下:

create table finaldsn as 
 select a.* 
 , b.* 
 , a.delivery_date-b.test_date as days 
 , abs(calculated days) as absdays 
 , min(calculated absdays)as close 
 from dsnA as a 
 full join 
 dsnB as b 
 on a.subject=b.id 
 where a.delivery_date ne . and b.ltest_datebdt ne . 
and b.id in (select distinct subject 
 from dsnA) 
 group by a.subject, a.delivery_date 
 having calculated absdays=calculated close 
;
quit;

这来自以下论文:http://www.lexjansen.com/pharmasug/2003/coderscorner/cc001.pdf,其中还提供了一些其他解决方案。

答案 1 :(得分:0)

您可以使用SAS功能INTCK计算样本日期和目标日期之间的差异,然后您可以保持更接近0的日期。

这是一个链接,因此您可以快速了解这些功能:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212868.htm

另外,请随时查看链接左侧的其他功能,因为从长远来看它们可以派上用场。