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

I am calculating the 

 

I have a table with date, Month and Year values stored as numeric. I need to calculate fiscal years

e.g. April 01 2016  to March 31 2017 then FY 20617 

I use the  month and year functions to get the month and year columns  How would I code to get fiscal years

 

Please advise 

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Assuming you have DAY, MONTH and YEAR values, you can get the SAS date with

 

date = mdy(MONTH, DAY, YEAR);

 

You can then get the SAS date corresponding to the first day of your fiscal year with:

 

firstFYdate = intnx("YEAR.4", date, 0, "Beginning");

 

and the SAS date of the last fiscal year day as:

 

lastFYdate = intnx("YEAR.4", date, 0, "End");

 

The datastep statement:

 

FORMAT date firstFYdate lastFYdate yymmdd10.;

 

will give a readable format to these SAS dates.

PG

View solution in original post

8 REPLIES 8
Ranjeeta
Pyrite | Level 9

data test;

input date MONTH YEAR

datalines;

17969 18554 18574

   3   10    11

 2009 2010 2010

;

 

I need to create a variable named FY e.g. 2009/10 would be if observation is in between April 01 2009 to March 31 2010

Thanksyou

PGStats
Opal | Level 21

Assuming you have DAY, MONTH and YEAR values, you can get the SAS date with

 

date = mdy(MONTH, DAY, YEAR);

 

You can then get the SAS date corresponding to the first day of your fiscal year with:

 

firstFYdate = intnx("YEAR.4", date, 0, "Beginning");

 

and the SAS date of the last fiscal year day as:

 

lastFYdate = intnx("YEAR.4", date, 0, "End");

 

The datastep statement:

 

FORMAT date firstFYdate lastFYdate yymmdd10.;

 

will give a readable format to these SAS dates.

PG
Ranjeeta
Pyrite | Level 9
Would you be able to advise how to write the if statemnt correctly I am getting an error as noted below:

data proceduresdate;
37 set procedures;
38 date=datepart(RemovalDate);
39 firstFYdate = intnx("YEAR.4", date, 0, "Beginning");
40 lastFYdate = intnx("YEAR.4", date, 0, "End");
41 FORMAT firstFYdate lastFYdate yymmdd10.;
42 FORMAT date Date9.;
43 if date between '01apr2009'd and '31mar2010'd then FY ='200910';
-------
388
202
ERROR 388-185: Expecting an arithmetic operator.

ERROR 202-322: The option or parameter is not recognized and will be ignored.

44 run;
PGStats
Opal | Level 21

BETWEEN is not recognized in this context. You must use

 

if '01apr2009'd <= date <= '31mar2010'd then FY ='200910';

PG
Ranjeeta
Pyrite | Level 9
thankyou
novinosrin
Tourmaline | Level 20
data fiscal_year;
do year=2000 to 2018;
do month=1 to 12;
   date=mdy(month,1,year);
   fedfiscalyear = year(date) + (month(date) gt 3);
	 output;
end;
end;
format date date9.;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 8 replies
  • 8433 views
  • 3 likes
  • 4 in conversation