Help using Base SAS procedures

Calculating from SQL to SAS Proc

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

Calculating from SQL to SAS Proc

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


Accepted Solutions
Solution
‎04-22-2013 07:56 AM
Super Contributor
Posts: 578

Re: Calculating from SQL to SAS Proc

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

View solution in original post


All Replies
Super User
Posts: 5,260

Re: Calculating from SQL to SAS Proc

DateDiff isn't SAS function as well.

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

Data never sleeps
Solution
‎04-22-2013 07:56 AM
Super Contributor
Posts: 578

Re: Calculating from SQL to SAS Proc

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

Contributor
Posts: 20

Re: Calculating from SQL to SAS Proc

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.



Contributor
Posts: 20

Re: Calculating from SQL to SAS Proc

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 683 views
  • 3 likes
  • 3 in conversation