# Program to select dates for seasonality

I am looking for a function (preferably SAS) that can read daily/weekly/monthly data from over a few years and select the two best dates to separate the year into two seasons (not necessarily of equal length), each with its own trend.

• Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
– Community Bot
Commented Nov 16, 2022 at 7:19
• If I understand correctly, you would like to (for instance) determine that everything from April to June is season 1, and everything from July to March is season 2, correct? If so, what makes one such partition better than another one? Are you looking for the largest difference in average observations between the two seasons? If so, the easiest approach is likely a brute force search over all possible pairs of delimiting dates in a year, possibly subject to minimum length constraints (you don't want a spurious "season" that is only three days long). Commented Nov 16, 2022 at 7:54
• Thanks. I am hoping to find a decision-tree-type algorithm or function which can find the dates (can also be in the middle of a month) which will define summer (in which there are fewer hip fractures, for example) and winter (in which there are more) that cna be used for all years. Commented Nov 16, 2022 at 8:07

Your best bet is likely a very simple double loop for an exhaustive search.

Loop over the possible dates in a year (or week starts, or month starts for weekly or monthly data). Call this $$t_1$$.

Loop over the possible later dates (week starts, month starts) in a year. Call this $$t_2$$. You may want to start your loop at $$t_1+\Delta$$ for some minimum season length $$\Delta$$.

For each pair $$(t_1, t_2)$$, calculate average observations $$\overline{y}_i$$ ("in-season") between $$t_1$$ and $$t_2$$, and average observations $$\overline{y}_o$$ ("out of season") between $$t_2$$ and $$t_1$$ (of the next year). Note the boundaries of your time series (which is why I would work with averages in seasons, not totals). Calculate the absolute difference $$|\overline{y}_i-\overline{y}_o|$$.

Finally, pick the pair $$(t_1, t_2)$$ with the largest difference $$|\overline{y}_i-\overline{y}_o|$$.

This should be easy to implement in any type of software, far easier than teaching some ML algorithm to output time intervals. Unless you need this in real time for massive numbers of time series (in which case I hope you would not be asking here), it should be also absolutely competitive in terms of runtime.

This could be just a comment, but I do offer it as a serious answer.

I have experienced several versions of this problem, when something like snow in Scotland or sunshine in Sydney shows a peak close to the turn of the common conventional calendar and using the conventional calendar for graphs and/or summary statistics is less than ideal.

It's worth pointing out that non-calendar years (meaning, years not starting on 1 January) are utterly standard in many areas, including religious, hydrological, fiscal and academic years.

The answer is indeed some kind of non-calendar year but in practice

1. If you start the year when values are low, or not of interest, it shouldn't much matter when you start.

2. If you try to optimize, you set up a subsidiary problem of what criterion or criteria to use, how to optimize, and what to do when your machinery indicates different starts in different years, and so forth. Unless your problem makes it natural, or a good idea, to define "years" with different lengths, the solution can create as many problems as it solves, and there is a real risk that what should be just an operational detail becomes a major distraction. And your problems don't stop there, as you have to explain what you did, including to other researchers who may think it's a bad idea or that they have a better idea.

3. I let convenience and consistency outvote all nuanced solutions and go for cuts like (the beginning of) July.

There is a miscellany of comments and examples in this paper. I thought up the title of the paper some years before I knew what it would say.

Note: Two seasons each with their own trend seems like a false goal to me. If rises and falls were essentially or even roughly triangular that could make sense, but fitting smoother trends lacking discontinuities with sinusoids is usually a better bet in my experience. (Economists have their own kind of answer, throwing lots of indicator variables into the fit.)