Desktop productivity for business analysts and programmers

Converting DATE YYYYMMDD10 to an academic year value

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

Converting DATE YYYYMMDD10 to an academic year value

[ Edited ]

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!


Accepted Solutions
Solution
‎07-02-2018 11:22 AM
Super User
Posts: 24,026

Re: Converting DATE YYYYMMDD10 to an academic year value

Posted in reply to runningjay

Did the code produce what you want then?

 


@runningjay wrote:

Yes - it is a numeric field with a date format.

 

Thanks


 

View solution in original post


All Replies
Super User
Posts: 24,026

Re: Converting DATE YYYYMMDD10 to an academic year value

Posted in reply to runningjay

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?

Super User
Posts: 13,942

Re: Converting DATE YYYYMMDD10 to an academic year value

Posted in reply to runningjay

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.

 

Occasional Contributor
Posts: 15

Re: Converting DATE YYYYMMDD10 to an academic year value

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!

Occasional Contributor
Posts: 15

Re: Converting DATE YYYYMMDD10 to an academic year value

Posted in reply to runningjay

I should have stated more clearly. The STARTDATE is a DATE field with a format of YYMMDD10., not YYYYMMDD10. as stated previously.

Super User
Posts: 24,026

Re: Converting DATE YYYYMMDD10 to an academic year value

Posted in reply to runningjay

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);

 

 

Occasional Contributor
Posts: 15

Re: Converting DATE YYYYMMDD10 to an academic year value

Yes - it is a numeric field with a date format.

 

Thanks

Solution
‎07-02-2018 11:22 AM
Super User
Posts: 24,026

Re: Converting DATE YYYYMMDD10 to an academic year value

Posted in reply to runningjay

Did the code produce what you want then?

 


@runningjay wrote:

Yes - it is a numeric field with a date format.

 

Thanks


 

Occasional Contributor
Posts: 15

Re: Converting DATE YYYYMMDD10 to an academic year value

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 152 views
  • 0 likes
  • 3 in conversation