Help using Base SAS procedures

numeric year convert to date

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

numeric year convert to date

I am trying to convert a numeric year to sas year date. The years are 2013 and 2014. When I have them converted, they are 1965 for both.

This gives me the numeric format for year: year=input(substr(compress(reporting_term,1,4),yy4.);

When I format the year using YEAR4., I am able to get the year formatted, but it gives me 1965.

Any assistance will be great.


Accepted Solutions
Solution
‎12-16-2014 11:12 AM
Super User
Posts: 5,099

Re: numeric year convert to date

SAS doesn't store years as dates.  It only stores individual days.  If you have a variable that takes on values of 2013, 2014, etc., you can convert them to a legitimate day using:

year = mdy(1, 1, year);

Then the year4 format would print just the year.  You're not storing the year, you're storing January 1st of that year.  But the format controls what will print.

Good luck.

View solution in original post


All Replies
Solution
‎12-16-2014 11:12 AM
Super User
Posts: 5,099

Re: numeric year convert to date

SAS doesn't store years as dates.  It only stores individual days.  If you have a variable that takes on values of 2013, 2014, etc., you can convert them to a legitimate day using:

year = mdy(1, 1, year);

Then the year4 format would print just the year.  You're not storing the year, you're storing January 1st of that year.  But the format controls what will print.

Good luck.

Super User
Super User
Posts: 7,430

Re: numeric year convert to date

Erm, just store the 2013 as a number as that is all it is.  Not sure why you would want a format on that as 2013 = 2013 nothing fancy.

Contributor
Posts: 24

Re: numeric year convert to date

Thank you!! That worked for what I needed!

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 1356 views
  • 0 likes
  • 3 in conversation