BookmarkSubscribeRSS Feed
Astounding
PROC Star

Another approach is possible, which is to create your own format using your own "business day" scale.  Assuming you have a list of holidays, you would need to create the equivalent of:

value busdt today='1'  tomorrow='2'  nextday='3' etc.

You have already made one key decision, which is if a date falls on a holiday or weekend, it should map to the same outcome as the next (rather than the previous) business day.  In that case, the programming will be easier if you work backwards.  Start with the final day of the time period you want to measure, equivalent to:

value busdt finalday = '9999'  prior day = '9998' etc.

The details of such a program are complex but relatively short.

The advantage of such a format as that you can save it permanently and use it (relatively) easily:

interval = input( put(ending_day, busdt.), 4. ) - input( put(starting_day , busdt.), 4.);

Using cntlin= data sets, it would be equally plausible to set up a separate format for each subject in a study where the "holidays" vary by subject.  The cntlin= data set can generate a separate, permanent format for each subject, using values for FMTNAME like pid001_, pid002_, etc.  Using these formats would be a little trickier.  You would have to switch from PUT to PUTN, to allow the name of the format to be data-driven based on the patient ID.

Good luck.

Reeza
Super User

Since your dataset doesn't have the holidays or weekends you could consider creating a list of distinct dates from that list and a second list of all dates. This will allow you to identify dates that are holidays/weekends and create a lookup table that has all the dates and count of the business days before.

I've done this before when constructing dimensions for BI implementations, though I usually hardcode the holiday dates b/c I'm in Canada and the holidays are different and let SAS takes care of weekends.

The lookup table comes in handy for other things as well, ie identifying/grouping quarter, fiscal years, calendar months, etc...

bkoksal
Calcite | Level 5

All this discussion seems tpo me that it makes the problem more difficult than it is.

First of all, for example, in islamic calendar dates of some religious holidays are according to the lunar calendar and they change every day. So it seems not managable to hardcode the dates.

I imagine that the easiest solution is this. Just download dates for an index from the stock exchange of the country in question. For US, it is SP500, for example. Since the stock exchange is closed for the holidays, there will not be dates for those days. Then use this "dates" dataset to calculate the business days between any two dates.

This approach makes the need to have a list of the holidays redundant.

bkoksal
Calcite | Level 5

I meant the dates for holidays in islamic calendar changes every year.

art297
Opal | Level 21

Then I'll leave it for the coauthor of our upcomming SGF paper to respond, as he is the one who wrote the code for building an Islamic calendar interval dataset.  I don't have any problem with posting it here in advance of SGF, as that way we can get some good tests of the code but, given it is his code, I'll leave the decision up to him.

FriedEgg
SAS Employee

The concept of islamic dates goes a far bit beyond the scope of the original question at hand.  I do not really want to hijack this thread with a large amount of irrelevant data but I will assure you that through the use of rather simple algorithms you can convert any islamic date to or from a 'normal' gregorian date.  Once you add this ability to SAS the task of finding the floating holiday dates becomes fairly trivial.  If anyone is interested in discussing this topic further feel free to start a new thread and I will gladly share more of the information from the upcoming SGF paper with everyone.

More relevant information to this topic:

If you look at the original link I shared regarding the usage of the holiday function to build a list of valid business days to use with intervalds option:

http://www.sascommunity.org/wiki/Generating_Holiday_Lists

You will see that the poster there did take into consideration that the actual holiday dates for certain events are observed in the business world on different days, like Reeza's example of New Years Day.

The reason there is not a simple isholiday() function is because this vary's far too much to just form a standard.  It is best and most reliable to build your function or using intervalds to accommodate all of your particular needs to deal with valid business days.  There are also events besides just holiday's you may want to account for.   For instance there may be certain events at a company which caused abnormal business closures at a given time.  Such as a power outage or a blizzard which you would want to account for also.

art297
Opal | Level 21

FriedEgg:  Just an FYI: the author of that sasCommunity.org page happens to be a Discussion Forum participant as well.  I'm surprised that he hasn't participated, as yet, in the present discussion.

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
  • 21 replies
  • 5957 views
  • 0 likes
  • 7 in conversation