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.
 A: 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.
A: 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

*

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


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


*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.)
