BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Question
Fluorite | Level 6

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
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

3 REPLIES 3
Astounding
PROC Star

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;

Question
Fluorite | Level 6
Thank You Astounding!
It's working 🙂

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Question
Fluorite | Level 6
Thank You Astounding!
It's working 🙂

##- Please type your reply above this line. Simple formatting, no
attachments. -##

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1047 views
  • 0 likes
  • 2 in conversation