I'm relatively new to SAS and I'm trying to create a new field based on the value in a variable titled STARTDATE formattted as DATE YYYYMMDD10. I want to use this variable to calculate a new variable labeled "FISCALYR". I need only the YYYY for this new variable, but I want it to be based on a fiscal year that runs from 07/01 to 06/30.
As an example if the STARTDATE is 20100625 I want the FISCALFY to reflect 2010. If the STARTDATE is 20100703 I want the FISCALFY to reflect 2011. I was thinking I could use the INTCK or INTNX functions, but I'm not sure how to make this work.
Thanks for the feedback!
Did the code produce what you want then?
@runningjay wrote:
Yes - it is a numeric field with a date format.
Thanks
What type and format are the date variables?
Are they numeric with a format applied such as yymmdd10, or are they a character and appear as 2018/06/28?
Before going any further please confirm that your Startdate variable is 1) numeric and 2) has an actual SAS Format of yymmdd10. If the SAS format is not a date format displaying the values the way you want then your value is basically just a number and the Date related functions and such will not work. Use proc contents or the SAS explorer to view column properties or such. I ask for clarification because there is no SAS supplied format yyyymmdd10. There is yymmdd10. however.
IF the value is a SAS date value then
Fiscalyear = year(datevariable) + (month(datevariable) > 6);
data example; input date mmddyy10.; format date yymmdd10.; Fiscalyear = year(date) + (month(date) > 6); datalines; 01/01/2016 06/20/2016 07/01/2016 ; run;
If your variable is not a date then you likely should actually turn it into an actual SAS date value as that makes things much easier. Best is usually to do so while reading or importing data.
Thanks for the suggestion and guidance. Both of the responses I received worked to achieve what I wanted to do including your suggestion. In looking back at my question I should have been more clear in what I was trying to do, but even with the lack of clarity you provided excellent guidance that provided what I needed. Thanks!
I should have stated more clearly. The STARTDATE is a DATE field with a format of YYMMDD10., not YYYYMMDD10. as stated previously.
Not being a pain, just a clarification, SAS only has two types, numeric and character. So its a numeric with a date format or a character.
I'm going to assume it's a date though in this case.
You can use the YEAR function to get the year component and the MONTH() function to get the month.
if month(date) <= 6 then fiscal_Year = catx('/', year(date)-1, year(date));
else fiscal_year = catx('/', year(date), year(date)+1);
Yes - it is a numeric field with a date format.
Thanks
Did the code produce what you want then?
@runningjay wrote:
Yes - it is a numeric field with a date format.
Thanks
Final solution I used was as follows:
if month(date) <= 6 then fiscal_Year = catx('/', year(date)-1, year(date));
else fiscal_year = catx('/', year(date), year(date)+1);
This provided the FISCAL YEAR formatted as needed. Thanks for the feedback especially given the lack of clarity in my original question.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.