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
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.
Please post usable example data in a data step with datalines; see my footnotes for hints.
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
You misplaced your data; change columns to rows and vice versa, so you get correct data. Test your data steps before posting.
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.
BETWEEN is not recognized in this context. You must use
if '01apr2009'd <= date <= '31mar2010'd then FY ='200910';
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;
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!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.