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

Hi Guys,

I was hoping someone could give me a hand working through this... I'm still working out what my tool set is in SAS...

Here is a piece of SQL code that I use to return the weeks active for a customer.

Basically it works out what Week Starting date was the week a custs first order was made, and the last day of the week for their most recent order.

It then works out the difference between the two and gives me an int value.

datediff(wk,dateadd(week, datediff(week, 0, c.FirstOrderDate),0), dateadd(week, datediff(week, 0, LastOrder), 6))

AS 'Weeks Active'

DateAdd doesn't appear to be in SAS.

I've been looking at SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition to try and work out how to make this work... But I'm getting confused.

Has anyone done this before_r

1 ACCEPTED SOLUTION

Accepted Solutions
DBailey
Lapis Lazuli | Level 10

intnx('week',LastOrder,0,'end') - intnx('week',c.FirstOrderDate,0,'Begin')

View solution in original post

4 REPLIES 4
LinusH
Tourmaline | Level 20

DateDiff isn't SAS function as well.

You can use INTNX() function to do this calculation.

Data never sleeps
DBailey
Lapis Lazuli | Level 10

intnx('week',LastOrder,0,'end') - intnx('week',c.FirstOrderDate,0,'Begin')

breelloyd
Fluorite | Level 6

intnx('week',LastOrder,0,'end') - intnx('week',c.FirstOrderDate,0,'Begin') will probably work,

I'm getting . for all fields. So I need to work out why that's happening. Both fields are formatted the same way.


I'll keep chipping away until I work it out.



breelloyd
Fluorite | Level 6

I got it to work. Thank you very much!!

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1249 views
  • 3 likes
  • 3 in conversation