BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jb9977
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

5 REPLIES 5
ballardw
Super User

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

Ksharp
Super User
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;
Patrick
Opal | Level 21

@Ksharp

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

Ksharp
Super User

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;

mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 692 views
  • 0 likes
  • 5 in conversation