BookmarkSubscribeRSS Feed
LaurieF
Barite | Level 11
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.
12 REPLIES 12
Reeza
Super User

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

LaurieF
Barite | Level 11
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.
Reeza
Super User

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

 

 

LaurieF
Barite | Level 11

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.

Reeza
Super User

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. 

art297
Opal | Level 21

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

 

Kurt_Bremser
Super User

@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.

LaurieF
Barite | Level 11

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.

Kurt_Bremser
Super User

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.

LaurieF
Barite | Level 11

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.

ballardw
Super User

@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.

ChrisNZ
Tourmaline | Level 20

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 12 replies
  • 1705 views
  • 6 likes
  • 6 in conversation