Hi,
In my dataset I have a date (document_date) listed in format DATE9. I would like to add an additional column which gives you the YEAR of 'document_date'. I've tried the following things, but it is not giving me the year. What am I doing wrong?
1. Add a computed column YEAR(t1.document_date) in format YEAR4 --> gives me 17JUL1965
2. Add t1.document_date as an additional column and give it format YEAR4 --> the output is the same as the input
Thank you in advance.
Both the YEAR function and the YEAR format expect an input value which represents a SAS date. SAS stores dates as counts of days, with 1960-01-01 being day zero.
Since the result of the YEAR function is not a SAS date, but the year number, applying the DATE format to the result will interpret this number as a count of days and come up with a year of 1965 for the value of 2024.
For the display of a year value like the number 2024, no format is needed. It's just a 4-digit number, unless you reached so far into the future that you went past 9999.
Your 2nd options sounds like something that should work.
data have;
document_date='25Feb2024'd;
run;
proc sql;
select
document_date
,document_date as document_date_2 format=date9.
,document_date as document_date_3 format=year4.
from have
;
quit;
Both the YEAR function and the YEAR format expect an input value which represents a SAS date. SAS stores dates as counts of days, with 1960-01-01 being day zero.
Since the result of the YEAR function is not a SAS date, but the year number, applying the DATE format to the result will interpret this number as a count of days and come up with a year of 1965 for the value of 2024.
For the display of a year value like the number 2024, no format is needed. It's just a 4-digit number, unless you reached so far into the future that you went past 9999.
Hi @Kurt_Bremser,
Thank you for your explanation. I've set the format to 'none' and now it indeed works!
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.