# SAS datdiff statement

#### noetsi

##### No cake for spunky
I ran this code

PROC SQL;
CREATE TABLE SASUSER."tab1"n AS
SELECT t1.VRID,
t1.CASE,
t1.STATUS,
t1.Area,
t1.Unit,
t1.DB10,
t1.DUR10,
t1.DURS10,
t1.DB12,
t1.DBCLO,
/* DIFF1012 */
(DATDIF(t1.DB10, t1.DB12, 'ACT/ACT')) AS DIFF1012,
/* D10CLO */
(DATDIF(t1.DB10, t1.DBCLO, 'ACT/ACT')) AS D10CLO
FROM WORK.CYCLETIME5 t1;
QUIT;

and get

NOTE: Invalid argument to function DATDIF. Missing values may be generated.
NOTE: Invalid argument to function DATDIF. Missing values may be generated.

I don't see any invalid argument there. I do get results.

#### Con-Tester

##### Member
It could be missing values (SQL “NULL” / SAS “.”).

Another possibility is that the variables “DB10”, “DB12” and “DBCLO” are of type “DATETIME” rather than type “DATE”. The “DATDIF()” function expects the “DATE” type as arguments. If the variables are indeed of type “DATETIME”, your code should extract the date part using SAS’s “DATEPART()” function:
Code:
	⁞
(DATDIF(DATEPART(t1.DB10), DATEPART(t1.DB12), 'ACT/ACT')) AS DIFF1012,
/* D10CLO */
(DATDIF(DATEPART(t1.DB10), DATEPART(t1.DBCLO), 'ACT/ACT')) AS D10CLO
⁞
Note also that if you use the “ACT/ACT” basis, you could simply subtract the one date from the other because SAS’s “DATE” type counts whole days from a base date (01 January 1960).

#### noetsi

##### No cake for spunky
They are dates although that is interesting to know.

There are in many cases missing values (I made them . so SAS would know they are missing, although they show NULL on the MS Server. I have found importing dates into SAS with NULL values leads sas to think they are a character field not a date field). I did not see anywhere in the documentation that says some of the rows can not be missing when you use this function (you get . of course as a result, but I only care about the rows that are not missing).

As far as I can tell it calculates the non-missing rows correctly. I was simply concerned about the warning (which I think now was tied to missing values). I think this warning is confusing, missing data is common in analysis I do.

Thank you very much.