A couple of issues I can identify: In SAS you just subtract dates, if its date times then you need to take the date part, unless you want the time in seconds or milliseconds, not sure what the smallest unit of date time is. Also there is no CASE statement, there's a SELECT statement, but an if/then is probably what you're looking for. Your SQL statement is merging, but your datastep code is APPENDING the dataset not merging. I'm not 100% sure what you want but the following is a start with the following assumptions: date is in datetime you want difference in terms of days Merging files by client id and id *First need to sort both files: proc sort data=data_333; by client id; proc sort data=test_data; by client id; *then need to merge and get differences; Data Test; MERGE data_333 (in=a) test_data (in=b); by client id; *get only records from data_333; if a; if datepart(cd_date)-datepart(add_date))<=1 then cd_1=1; else cd_1=0; if datepart(cd_date)-datepart(add_date)<=2 then cd_2=1; else cd_2=0; run; OR SQL create table test as select a.add_date ,b.cd_date ,case when datepart(b.cd_date)-datepart(a.add_date) <= 1 then 1 else 0 end as cd_1 ,case when datepart(b.cd_date)-datepart(a.add_date) <= 1 then 1 else 0 end as cd_2 from data_333 a left join test_data b on a.client = b.client and a.id = b.id; quit;
... View more