Hi! I have a dataset which includes person IDs and one record for each of their transactions, looking something like this: UIN PURCHASEID CREATIONDATE ID_0045 60636 11-May-17 ID_0073 60646 13-Aug-17 ID_0073 63179 28-Dec-17 ID_0073 64001 07-Aug-18 ID_0084 61952 01-Aug-17 ID_0084 60539 01-Jun-18 ID_0092 60686 13-May-17 ID_0092 63302 28-May-18 ID_0092 60465 07-Aug-18 I want to create a code that flags when a person has made a purchase both in this past 12 months, and as well as having made a purchase during the previous 12 months, so that it may look something like this: UIN PURCHASEID CREATIONDATE FLAG ID_0045 60636 11-May-17 0 ID_0073 60646 13-Aug-17 1 ID_0073 63179 28-Dec-17 1 ID_0073 64001 07-Aug-18 1 ID_0084 61952 01-Aug-17 0 ID_0084 60539 01-Jun-18 0 ID_0092 60686 13-May-17 1 ID_0092 63302 28-May-18 1 ID_0092 60465 07-Aug-18 1 I'm not sure how exactly to go about this. I tried to use a dataset grouped by UIN (the dataset is already sorted by UIN) but this did not work as each record only has one creationdate. And, this is working from a fixed point in time so would not work for my whole dataset anyway. data purchases2;
set purchases1;
by UIN;
if (creationdate between '08aug2017'd and '07aug2018'd)
and (creationdate between '08aug2016'd and '07aug2017'd)
then flag=1; else flag=0;
run; This seems quite complex but I'm hoping there's a simple solution! Thank you! 🙂
... View more