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
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.
First, is your "date" a SAS date valued numeric or character?
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;
Hmmm... Does your week calculation work 100% when it comes to leap years?
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;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.