DATA Step, Macro, Functions and more

Using 'day' interval in intnx and intck

Reply
Super Contributor
Posts: 251

Using 'day' interval in intnx and intck

Can someone explain why anyone would use 'day' as an interval parameter, since day is ipso facto the granular date? Code example: "intnx('day', todaydate, -200)" cf "todaydate - 200".

I'm flummoxed.
Super User
Posts: 17,836

Re: Using 'day' interval in intnx and intck

If it was some type of dynamic calculation where the parameters were user defined. Then one formula could be used to be generic.  

Super Contributor
Posts: 251

Re: Using 'day' interval in intnx and intck

Yeah, but that's so much of an edge case it's fallen off the side of the planet. I take your point, but I'm not buying it.

I'd much rather keep things simple.
Super User
Posts: 17,836

Re: Using 'day' interval in intnx and intck

Another viewpoint then, if you were developing the function would you have excluded day as an option? 

 

 

Super Contributor
Posts: 251

Re: Using 'day' interval in intnx and intck

No, I would of course include it. If I were master of the universe, I'd make the (pseudo-)code have a select for 'day' and use the arithmetic approach - if that isn't how it's done already.

 

But I would also update the documentation to recommend for single day calculations to do it without the functions.

Super User
Posts: 17,836

Re: Using 'day' interval in intnx and intck

I actually am not a fan of the month interval personally because it's not a standard measure. It makes things easier for people to understand but from a comparison or duration perspective it's not a good metric. 

 

For calculating number of days, I would use basic math operations as well. 

PROC Star
Posts: 7,363

Re: Using 'day' interval in intnx and intck

Since one can include multiples and shift indexes with any interval, it can simplify coding when they're needed.

 

Other than that yes, I too, typically only do the math when I need to increase or decrease dates.

 

Art, CEO, AnalystFinder.com

 

Super User
Posts: 6,939

Re: Using 'day' interval in intnx and intck


LaurieF wrote:
Yeah, but that's so much of an edge case it's fallen off the side of the planet. I take your point, but I'm not buying it.

I'd much rather keep things simple.

Then your planet is awfully small. Consider reclassifying it as an asteroid.

Just think of a stored process where a timespan can be dynamically entered as a combination of (prompt A) multiples and (prompt B) intervals, where one of the intervals might be days. Then you would have to use extra code for days if the intnx didn't support that.

And that would be REAL stupidity squared.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 251

Re: Using 'day' interval in intnx and intck

[ Edited ]

D--n, that was harsh. And unncessary. Please don't try to teach grandpa how to suck eggs. I am very well aware of these, but that was not the point.

 

It is an edge case. The code I showed was base SAS code (contained within a DI user-written transformation) and it was exactly as I wrote it (on my phone). It wasn't part of a drop-down selection, it wasn't "DAY.2" or anything fancy like that. I accept that these are reasonable responses to my mini-rant that started off, but they are the exception.

 

I come across this usage of intnx and intck in virtually every site I work at, and it annoys me greatly. It makes the maintenance of the code harder, and it also makes it harder to read. It also shows a probable lack of understanding by whoever wrote the code of how SAS dates inherently work.

 

It is of course a requirement of the intxx functions to accept 'day'. It doesn't mean that people should use it.

Super User
Posts: 6,939

Re: Using 'day' interval in intnx and intck

I may have misunderstood your rant (and one follow-up post) as being against the presence of the day interval vs. being against the (unreflected) use of it. Apologies.

 

But the use of the function can make sense in view of other aspects:

- it disconnects the logical calculation from the physical calculation. This helps in porting code to other systems that may do dates differently, but have similar functions

- it hardens against any change in how SAS deals with variables (which is, of course, unlikely to the extreme)

- it helps in preparing against type changes (date to datetime happens often in databases, and it has happened with our so-beloved Excel); one can then keep the code and needs to only replace 'day' with 'dtday', which may help in automated changes to a codebase.

 

But I am with you that in >90% of cases it is proper to use a simple addition/subtraction instead of intnx when dates and days are involved. Both in terms of KISS and performance.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 251

Re: Using 'day' interval in intnx and intck

First point - most other systems I've used use a base-dating system, whether it be 1Jan1960, 1Jan1901 or similar, and allow day arithmetic.

 

Second point - won't happen. All of SAS's date handling would break.

 

Third point - shrug. Except for day multiples ('day.2' et al) (and I've never personally had a reason to use them), I'll keep on using arithmetic, and counselling and training for its use.

 

Today I saw:

intck('month', intnx('month', startdte, 0, 'b'), intnx('month', endte, 0, 'b'))

instead of

intck('month', startdte, endte)

It is possible to argue that there may be a reason to use the former, for possible later modification. I would wager a reasonable amount of beer that that time will never come.

 

Make it as simple as possible, but no simpler.

Super User
Posts: 10,500

Re: Using 'day' interval in intnx and intck


LaurieF wrote:
Yeah, but that's so much of an edge case it's fallen off the side of the planet. I take your point, but I'm not buying it.

I'd much rather keep things simple.

Day would be the base of the Day2, Day3, Day4, Dayx intervals

Not to mention the DtDay.

 

An I believe it does "keep things simple". Without out the Day (or eqivalent Second for time/datetime) you would NOT be able to have exactly parallel code but would have to conditionally substitute subtraction or addition.

PROC Star
Posts: 1,561

Re: Using 'day' interval in intnx and intck

[ Edited ]

1- As @Reeza mentionned, if the day measure wasn't there, there would be a gap and some people would (rightfully) ask where on earth it is.

2- As @art297 mentionned, multiples and shift indexes are so very powerful
3- and it can all be programmatically driven (as @Reeza also mentionned)

 

 a=intnx('day2', '01jan2010'd, 10); put a= date9.; %*  Add ten 2-day periods;

a=20JAN2010

Ask a Question
Discussion stats
  • 12 replies
  • 268 views
  • 6 likes
  • 6 in conversation