It must be clearly understood that SAS has
just two data types, namely text and numeric. The numeric data type is in all cases the
IEEE 754 double-precision floating-point type (8-byte real). SAS doesn’t even distinguish between integer and floating-point numeric types; all numeric types are stored in the same way. It’s the SAS format that’s associated with a particular numeric data column that determines how SAS shows the data to the user, e.g., date, currency, time, representation (scientific, engineering, general), how many decimal places, etc. It is important to understand this aspect of SAS because it often clears up basic misunderstandings.
What the above means is that
there’s no requirement that a date value must have a date format before it can be passed to a date function. Or, for that matter, that any type-specific numeric calculation requires that the arguments have the correct format before the function will process them. All that’s needed is that the underlying values of the numeric variables are within the allowable range. That is to say,
the associated format is irrelevant and is merely a convenience for humans viewing the data.
All of that said, I suspect the reason NULL values are returned by “datdif(datevariable1,datevariable2,"actual")” is that either (1) “datevariable1” or “datevariable2” is NULL, possibly both, and/or (2) that one or both of them are outside the allowable range. Reason (2) could happen if the variables are “datetime” types rather than “date” types (the value mappings are
very different between these two types), and the correct date value can be extracted from a datetime variable using the SAS function “datepart(DateTimeVar)”.
If you know for a fact that the two variables are proper non-NULL SAS dates then hlsmith’s method will give the number of days between “datevariable1” and “datevariable2” because SAS’s date representation counts the integer number of days from a base date (01 January 1960).
See more here.