BookmarkSubscribeRSS Feed

...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.

5 Comments
PaigeMiller
Diamond | Level 26

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.

Astounding
PROC Star

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.

tomrvincent
Rhodochrosite | Level 12

@ if the number is formatted as a datetime, date functions should work on it.

PaigeMiller
Diamond | Level 26

@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.

tomrvincent
Rhodochrosite | Level 12

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.