Hello everybody,
perhaps someone knows this gem:
When using the datetime18. format, SAS does display the year with the last two digits only.
That is even documented over here: SAS 9.4 Formats and Informats - DATETIMEw.d
Now I am wondering why that is. 18 Characters would be enough to display the year with 4 digits and have enough space for all the rest (day, month, time, separators).
So this: "01JAN2015:00:00:00" could be a perfect datetime18. value, but instead it is this: " 01JAN15:00:00:00".
Does anyone know the reasons behind this?
One thought was that they might save some space for years greater than 9999, when the year would require 5 digits, but then again, regardless of the datetime width, years greater than 9999 are always displayed as '****'. So this should not be the reason.
Cheers,
Michael
Seems quite clear in that link you give. If its 18. then it is padded with two spaces, this is due to the fact that it leaves room for the seconds optional part.
Note that a datetime past year 9999 does display 2 digit years with datetime18. but not 5 digits
data _null_; x = '10MAR15021'd; y = dhms(x,0,0,0); put y datetime18. y datetime20. y datetime22. y datetime32.; run;
@RW9: well, leaving space for parts of seconds could be an explanation for datetime18. (although datetime18. could display the full year, whereas datetime18.1 should display only a 2 digit year)
If leaving space for parts of seconds is the explanation, then why does datetime19. display a 4 digit year? This leaves only 1 space. So adding parts of second does not fit, because the separator would fill the one space left, so there is no more space for any value.
datetime19. => 4 digit year
datetime19.1 => 2 digit year
IMHO datetime18. and datetime18.1 should work exactly like that since I would expect somewhat of a consistent behaviour
@ballardw: yeah that's true. Might be an indication that 2 digit year is sort of hard coded for datetime18. ?
Proc format with the Picture date/time directives will let you roll your own datetime format. Here is an example of 18 character with 4 digit year.
proc format library=work; picture mydatetime ( default=18) low-high = "%d%b%Y:%H:%M:%S" (datatype=datetime) ; run; data _null_; x='15Feb2017:10:12:13'dt; put x mydatetime. x datetime18.; run;
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.