• Status: Solved
• Priority: Medium
• Security: Public
• Views: 402

# date difference for time lag

I have two dates MailedToCust, Incident Date both in yymmdd10. format i want to datediff or time lag
sumting like this Calculated:  DateDiff (MailedToCust, Incident Date)
0
sam2929
• 2
1 Solution

Commented:
if both are dates (as i imply from your post), then it's simply date1 - date2 and format the column as best.

e.g.
data [output];
set [input];
date_diff = MailedToCust - IncidentDate;
format date_diff best.;
run;
0

Commented:
Hi

Iowa's result will work - but for a more general solution - SAS uses a function called INTCK to calculate differences in times. The nice thing, is one can calculate other time periods:

For instance ; INTCK("Month", Date1, Date2) calculates the difference in months between Date1 and Date2 by months.  The SAS help is very good with the descriptions on this one.

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212868.htm
0

Author Commented:
Does INTCK have DAY function too?
INTCK("Day", Date1, Date2)
0

Commented:
Hi

Yes it does...

Here are some of the options:

(For Time variables)
SECOND - each second
MINUTE - each minute
HOUR - each hour

(For Date variables)
DAY - each day
WEEKDAY - each weekday (Monday through Friday by default)
WEEK - each Sunday
TENDAY - the First, Eleventh, and Twenty-first of each month
SEMIMONTH - the first and sixteenth of each month
MONTH - the first of each month
QTR - the first of January, April, July, and October
SEMIYEAR - the first of January and July
YEAR - the first of January

(For DateTime variables)
DTDAY - each day
DTWEEKDAY - each weekday (Monday through Friday by default)
DTWEEK - each Sunday
DTTENDAY - the First, Eleventh, and Twenty-first of each month
DTSEMIMONTH - the first and sixteenth of each month
DTMONTH - the first of each month
DTQTR - the first of January, April, July, and October
DTSEMIYEAR - the first of January and July
DTYEAR - the first of January
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.