Differences between two dates

noetsi

Fortran must die
#1
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;
 
#3
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.
 

noetsi

Fortran must die
#4
I should have looked at the log to start with con-tester :(

The problem was that datebegin_14 was a datetime field and not a date field. T SQL which I have used in the past does not care about that, but SAS does.

This works INTCK("day",DATEPART(t1.DATEBEGIN_14) , "30APR2017"D)

thanks for your help. You should do PROC SQL. That way I could ask more question :)