...should work on datetime fields without having to use the datepart function. day(datetime1) should work. Also, date formats should work on datetime fields. Date9, for example, should show the standard ddmmmyyyy display.
I think the problem with doing this is that some numeric values cannot be uniquely determined to be a date or a datetime.
A value of 1846147693 can't be a date, it has to be a datetime. But a value of 21367 could indicate July 2, 2018 or it could indicate a datetime of around 6am on 01JAN60.
Note that SAS has started to address this, by creating formats that print datetimes in a date format. See these examples: DTDATEw., DTMONYYw., DTWKDATXw., DTYEARw., DTYYQCw.
You still need to know which of your variables are datetimes, and apply the formats in the appropriate cases.
@ PaigeMiller if the number is formatted as a datetime, date functions should work on it.
@tomrvincent Is this an additional requirement for this idea? That a format exists for the variable? I am not aware of any SAS calculation functions where the behavior of the function depends on the format of the variable used in the function.
But this doesn't really address my point. SAS date values, and SAS datetime values are just numbers. What if someone writes code and doesn't apply a format, because the usage in the program doesn't require a format? Then the decision of whether the number is a date or a datetime is ambiguous.
If it's 'just a number', it really isn't a date or a datetime. I think *all* date functions (month, day, etc.) should *only* work on dates/datetimes. That's the only times they are relevant.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.