Here is some code (sorry, spacing seems a bit weird on here). Have just done it quickly, so there is no checking done (i.e. if there are not previous transactions etc.) but it works. There are other methods, such as datdiff if you can specify a number of days rather than months. --- /* Create some test data */ data previous_transactions; attrib cust_id format=8. tran_date format=date9.; cust_id=1; tran_date='01mar13'd; output; cust_id=1; tran_date='06jan13'd; output; cust_id=1; tran_date='15may13'd; output; cust_id=2; tran_date='01mar13'd; output; cust_id=2; tran_date='03mar13'd; output; run; data new_transactions; attrib cust_id format=8. tran_date format=date9.; cust_id=1; tran_date='30may13'd; output; cust_id=2; tran_date='10oct13'd; output; run; /* New table with flag. */ proc sql; create table new_transaction_with_flag as select A.*, /* If the maximum date from previous transactions + 6 months is after the date we are looking at then we know this is within 6 months */ case when intnx('month',B.TRAN_DATE,6)>=A.TRAN_DATE then "Y" else "N" end as FLAG from WORK.NEW_TRANSACTIONS A /* Join on the maximum data from previous transactions */ left join ( select distinct CUST_ID, MAX(TRAN_DATE) as TRAN_DATE from WORK.PREVIOUS_TRANSACTIONS group by CUST_ID ) B on A.CUST_ID=B.CUST_ID; quit;
... View more