Last Week of Quarter

Monday, 19 May, 2014

⨳ 2 minute read ⨳ 428 words ⨳ date valuessas

A coworker recently asked me how I would identify the last week of a quarter when the date variable is formatted as week.2.

Here’s what I came up with.

data _null_;
    do i = 0 to 250;
        X_DT=intnx('week.2','01jan2010'd, i);
        last_week_of_quarter = (qtr(X_DT) ne qtr(intnx('week.2', x_dt, 1)));
    end;
run;

Which flagged the following dates as beginning in the last week of the quarter:

That looked good to me. All the flagged weeks we indeed at the end of the quarter.

Then the additional requirement that the X_DT values are set to the end of the week (Sunday), rather than the beginning (Monday). That throws a wench in things.

My initial thought was to simple add the 'e' argument to the initial intnx function. But that didn’t work.

These dates are weeks that end on the last day of the quarter. That’s not quite what he was after.

Adding the 'e' argument to the second intnx function as well seemed to fix things:

Which is the list of the last week that ends within a given quarter.


Last Week of Quarter - May 19, 2014 - Richard Koopmann