# Differences between two dates

#### noetsi

##### No cake for spunky
I am trying to find how many days occurred between datebegin_14 and April 30, 2017. This generates no error but also no results for the field duration I am trying to use to do this. I assume I am specifying the data April 30 2017 wrong, but I do not know the right answer.

PROC SQL;
CREATE TABLE SASUSER.out3 AS
SELECT t1.CUSTOMERID,
t1.CASENUMBER,
t1._TEMG001,
t1.COUNSELOR_PRI,
t1.DATEBEGIN_14,
/* Duration */
(INTCK('day',t1.DATEBEGIN_14, '30APR2017'd)) LABEL="Duration" AS Duration,
t1.STATUSCASE,
t1.DISTRICT_PRI,
t1.UNITID_PRI,
t1.INDIVIDUALLNAME,
t1.INDIVIDUALFNAME,
t1.STAFFLNAME,
t1.STAFFFNAME
FROM SASUSER.OUT2 t1;
QUIT;

#### bugman

##### Super Moderator
I thought this was an R question - so I came here by mistake!

Last edited:

#### Con-Tester

##### Member
I’d use native SAS code instead of PROC SQL. I’ll assume the SASUSER library has in it the input dataset OUT2.
Code:
DATA	SASUSER.OUT3;
SET	SASUSER.OUT2
(KEEP =	CUSTOMERID
CASENUMBER
_TEMG001
COUNSELOR_PRI
DATEBEGIN_14
STATUSCASE
DISTRICT_PRI
UNITID_PRI
INDIVIDUALLNAME
INDIVIDUALFNAME
STAFFLNAME
STAFFFNAME);
LABEL	Duration = "Duration";
Duration = INTCK("DAY", DATEBEGIN_14, "30APR2017"D);
RUN;
If the above fails, SAS’s log will give some indication as to why. My suspicion would be that the DATEBEGIN_14 variable is not a valid SAS date value: its type should be numeric, length 8 and its format that of a date.