我在SAS中有一个看起来像这样的通信日志ComLog
data ComLog;
input mail $ SendDate:date.;
format SendDate date.;
cards;
A@a 27Jan2013 1
A@a 29Jan2013 2
B@b 1Mar2013 3
C@c 3Mar2013 4
;;;;
run;
我还通过外部系统发送一些电子邮件,我正在尝试mapp接收者是否打开了电子邮件。文件BackToComLog看起来像这样,
data BackToComLog;
input mail $ ReadDate:date.;
format ReadDate date.;
cards;
A@a 28Jan2013
A@a 30Jan2013
B@b 2Mar2013
C@c 3Mar2013 .
;;;;
run;
现在,我试图将BackToCoMLog加入ComLog。我的最终文件应该是这样的
Mail SendDate OpenDate
A@a 27Jan 28Jan
A@a 29Jan 30Jan
B@b 1Mar 2Mar
C@c 3Mar 3Mar
我在这样的数据步骤中试过了这个,
proc sort data=ComLog;
by mail SendDate;
run;
proc sort data=BackToComLog;
by mail ReadDate;
run;
data want;
do until (last.mail);
merge ComLog BackToComLog;
by mail;
if first.mail or (range(OpenDate, SendDate) > range(ReadDate, SendDate)) then OpenDate = ReadDate;
end;
format OpenDate date9.;
drop ReadDate;
run;
这让我更进一步,但我的最终档案最终会像这样,
mail SenDate OpenDate
A@a 29JAN13 28JAN2013
B@b 01MAR13 02MAR2013
C@c 03MAR13 03MAR2013
因此,我的A @ a for 27Jan2013不在最终文件中,日期也是混合的。我需要代码能够在彼此之后使用不同的日期处理相同的邮件。
答案 0 :(得分:1)
试试这个:
PROC SQL;
CREATE TABLE result_table as
SELECT *
FROM ComLog AS t1
LEFT JOIN BackToComLog AS t2 ON t1.Mail = t2.Mail
WHERE t1.SenDate < t2.OpenDate
;
QUIT;