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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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