Converting a numeric year to a date formatted year

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

Converting a numeric year to a date formatted year

I have a SAS dataset that has a variable, fiscyear, that are years, but are formatted as numeric. I'm trying to convert that variable to a YEAR4. format so that I can use the years as dates in a proc. The code I'm trying to use (shown below) is producing this error:

NOTE 485-185: Informat YEAR was not found or could not be loaded.

I don't understand why I get this error. Is there a different method I could be using? My code is shown below.

/* Convert fiscyear to date format */

data work.project_new (drop=fiscyear);

  set WORK.project_old;

  charyear = put(fiscyear,4.);

run;

data work.project_new (drop=charyear);

  set work.project_new;

  fiscyear = input(charyear,year4.);

  format fiscyear year4.;

run;


Accepted Solutions
Solution
‎07-13-2014 08:11 PM
Super User
Posts: 3,252

Re: Converting a numeric year to a date formatted year

Posted in reply to klappy711

You are trying to use YEAR as an INFORMAT, when it only exists in SAS as a FORMAT. This means it will only work when you already have a SAS date and you apply it with a PUT function or FORMAT statement.

Try this instead:

fiscyear = mdy(1, 1, input(charyear, 4.));

format fiscyear year4.;

To create a SAS date you also need to tell SAS the day and the month of your date, so that fiscyear actually stores 1 Jan 2014, for example.

View solution in original post


All Replies
Contributor
Posts: 26

Re: Converting a numeric year to a date formatted year

Posted in reply to klappy711

The error occurs in the statement: fiscyear = input(charyear,year4.);

Is this because year4. is not an acceptable informat?

Solution
‎07-13-2014 08:11 PM
Super User
Posts: 3,252

Re: Converting a numeric year to a date formatted year

Posted in reply to klappy711

You are trying to use YEAR as an INFORMAT, when it only exists in SAS as a FORMAT. This means it will only work when you already have a SAS date and you apply it with a PUT function or FORMAT statement.

Try this instead:

fiscyear = mdy(1, 1, input(charyear, 4.));

format fiscyear year4.;

To create a SAS date you also need to tell SAS the day and the month of your date, so that fiscyear actually stores 1 Jan 2014, for example.

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 1670 views
  • 0 likes
  • 2 in conversation