Hi All,
I would like to create the fiewl week_return based on the tranasaction dates. For axmple this customer reatuns after 1 week, then after 2 weeks etc..Your help would be much appreciated.
Thank You
customer_id | WEEK_NO | Trans_date | weekly_latest_Sales | Week_return |
50026 | 1 | 06-Jan-17 | 31,000,000 | |
50026 | 2 | 13-Jan-17 | 53,000,000 | 1 |
50026 | 7 | 14-Feb-17 | 39,000,000 | 5 |
50026 | 10 | 10-Mar-17 | 64,000,000 | 3 |
50026 | 11 | 14-Mar-17 | 70,000,000 | 1 |
50026 | 13 | 31-Mar-17 | 49,000,000 | 2 |
It looks like you are using WEEK_NO to compute the difference (rather than TRANS_DATE) ... either way is perfectly fine. As long as your data set is sorted by CUSTOMER_ID, you can use:
data want;
set have;
by customer_id;
week_return = dif(week_no);
if first.customer_id then week_return=.;
run;
It looks like you are using WEEK_NO to compute the difference (rather than TRANS_DATE) ... either way is perfectly fine. As long as your data set is sorted by CUSTOMER_ID, you can use:
data want;
set have;
by customer_id;
week_return = dif(week_no);
if first.customer_id then week_return=.;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.