if i understand your objective correctly, i believe this code should do the trick: data OriginalData;
infile datalines delimiter=',';
input date :ddmmyy10. agreement_number $ outcome $ ;
format date ddmmyy10.;
datalines;
05/11/2020,1000,Answered
06/11/2020,1001,Answered
08/11/2020,1002,Not Answered
08/11/2020,1003,Answered
;
data Data1;
infile datalines delimiter=',';
input agreement_number $ date :ddmmyy10.;
format date ddmmyy10.;
datalines;
1000, 06/11/2020
1000, 07/11/2020
1001, 06/11/2020
1001, 07/11/2020
1001, 08/11/2020
1001, 09/11/2020
1002, 08/11/2020
1003, 08/11/2020
1003, 08/11/2020
;
PROC SQL;
CREATE TABLE work.dataMaxDate AS SELECT agreement_number, Max(Date) as MostRecentDate FROM work.data1 GROUP BY agreement_number;
CREATE TABLE work.final AS
SELECT
a.*
,CASE when b.MostRecentDate is not null then 1 else 0 end as New_Var
FROM
originaldata a
LEFT JOIN work.dataMaxDate b on a.agreement_number = b.agreement_number and b.MostRecentDate >= a.date and b.MostRecentDate < a.date+2
;
QUIT; note that you want to look at the work.final table. good luck
... View more