Solved
Contributor
Posts: 20

Customizing a fiscal year

Hello,

Is there a way where I can start my fiscal year on 1june and start the count of the week from that date? for example

Date         week

1jun2018     1

2jun2018      1

3jun2018       2

week starts on Sunday.

Thanks

Accepted Solutions
Solution
3 weeks ago
Posts: 1,345

Re: Customizing a fiscal year

Fiscal years are typically assigned a name corresponding to the year including the majority of months.  So fiscal year June 2009-May 2010 is usually called FY2009.   (July-June fiscal years, having 6 months in each calendar year, are commonly given an FY value corresponding to the year in which June falls - i.e.   July 2009-June 2010 usually called FY2010).

SAS date functions support the use of fiscal years easily.  In your case the yearly interval is designated as "YEAR.6"  (years beginning in June).  To do you task, you need (1) to determine the first date of the fiscal year in which the date-in-hand falls (using the INTNX functions), then (2) count weeks (using INTCK):

``````data want;
set have;
fybegin=intnx('year.6',date,0,'BEGIN');
weeknum=1+intck('week',fybegin,date);
run;``````

Of course, the 'week'  (which is the same as week.1) counts weeks as starting with Sundays.   If you need weeks starting with, say Mondays, use "week.2" as the interval measure in INTCK function.

All Replies
Super User
Posts: 13,583

Re: Customizing a fiscal year

First, is your "date" a SAS date valued numeric or character?

Super User
Posts: 10,784

Re: Customizing a fiscal year

``````data want;
do date='01jan2015'd to '01jul2018'd;
fiscal_year=year(intnx('year.6',date,0,'b'));
week=week(date-('01jun2018'd-'01jan2018'd),'v');
output;
end;
format date date9.;
run;
``````
Posts: 4,736

Re: Customizing a fiscal year

@Ksharp

Hmmm... Does your week calculation work 100% when it comes to leap years?

Super User
Posts: 10,784

Re: Customizing a fiscal year

Patrick,

I don't know. Can you post an example to explain it .

If my code doesn't work. Data step come to rescue .

data want;

set have;

by fiscal_year;

if first.fiscal_year then do;n=0;week=0;end;

n+1;

if mod(n,7)=1 then week+1;

run;

Solution
3 weeks ago
Posts: 1,345

Re: Customizing a fiscal year

Fiscal years are typically assigned a name corresponding to the year including the majority of months.  So fiscal year June 2009-May 2010 is usually called FY2009.   (July-June fiscal years, having 6 months in each calendar year, are commonly given an FY value corresponding to the year in which June falls - i.e.   July 2009-June 2010 usually called FY2010).

SAS date functions support the use of fiscal years easily.  In your case the yearly interval is designated as "YEAR.6"  (years beginning in June).  To do you task, you need (1) to determine the first date of the fiscal year in which the date-in-hand falls (using the INTNX functions), then (2) count weeks (using INTCK):

``````data want;
set have;
fybegin=intnx('year.6',date,0,'BEGIN');
weeknum=1+intck('week',fybegin,date);
run;``````

Of course, the 'week'  (which is the same as week.1) counts weeks as starting with Sundays.   If you need weeks starting with, say Mondays, use "week.2" as the interval measure in INTCK function.

☑ This topic is solved.