Lapis Lazuli | Level 10

## difference between date

This code has worked for me in the past, but not today. Can you please help suggesting what I'm doing wrong?

I have this error in the log NOTE: Invalid argument to function INTCK('days',21311,20061221) at line 498 column 16.

data diff;

set penality;
by Number;

days_between = intck('days',Penalty_Date,lag(Penalty_Date));

if first.Number then call missing(days_between);

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: difference between date

You do realize that your first data step doesn't generate valid data?

That's the reason. Fixing that so that penalty_date is a SAS date, which I saved into a new variable makes it work perfectly fine.

``````data penality;
input Number \$ penalty_date ;

datalines;
1 20061221
1 20180507
2 20140710
2 20171002
;

data penality2;
set penality;

penalty_sas_date = input(put(penalty_date, 8.), yymmdd10.);
format penalty_sas_date yymmdd10.;
run;

data diff;

set penality2;
by Number;

days_between = dif(penalty_sas_date);

if first.Number then call missing(days_between);

run; ``````
5 REPLIES 5
Rhodochrosite | Level 12

## Re: difference between date

The result of lag(Penalty_Date) is 20061221, which I think is an ERROR because it is beyond the range that can be handled by SAS date values.
Can you provide the actual data for the OBS before and after this?
Super User

## Re: difference between date

A date value of 20061221 (20 million days after 1960-01-01) falls somewhere in the late 55th millenium, so the function can't handle that and tells you so.

Looks like someone entered a date in a silly way.

Also, since SAS dates are counts of days anyway, your formula can be simplified as

``days_between = lag(Penalty_Date) - Penalty_Date;``

which will be faster than the function call.

Super User

## Re: difference between date

INTCK requires SAS date arguments.

20161221 is not a SAS date.

Here's a great, but longer and in depth, reference for dates and times in SAS
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/...

But since you're referring to the same variable that also doesn't make logical sense. Assuming your date is an actual SAS date, numeric with a date format then you can use the DIF function instead. If not, I'd convert it first and then use the DIF approach. If you need to convert it to a SAS date from a character it would be:

``date = input(penalty_date, yymmdd10.);``

Then:

``````data diff;

set penality;
by Number;

days_between = dif(penalty_date);

if first.Number then call missing(days_between);

run;``````

FYI - please use code blocks in future posts to have your code show up cleanly and formatted.

@sasphd wrote:

This code has worked for me in the past, but not today. Can you please help suggesting what I'm doing wrong?

I have this error in the log NOTE: Invalid argument to function INTCK('days',21311,20061221) at line 498 column 16.

data diff;

set penality;
by Number;

days_between = intck('days',Penalty_Date,lag(Penalty_Date));

if first.Number then call missing(days_between);

run;

Lapis Lazuli | Level 10

## Re: difference between date

hello,

it seems not working. this is a sample of my data

``````data penality;
input Number \$ penalty_date;
format Penalty_Date yymmdd10.;
datalines;
1 20061221
1 20180507
2 20140710
2 20171002
;

data diff;

set penality;
by Number;

days_between = dif(penalty_date);

if first.Number then call missing(days_between);

run; ``````

this is the output

Super User

## Re: difference between date

You do realize that your first data step doesn't generate valid data?

That's the reason. Fixing that so that penalty_date is a SAS date, which I saved into a new variable makes it work perfectly fine.

``````data penality;
input Number \$ penalty_date ;

datalines;
1 20061221
1 20180507
2 20140710
2 20171002
;

data penality2;
set penality;

penalty_sas_date = input(put(penalty_date, 8.), yymmdd10.);
format penalty_sas_date yymmdd10.;
run;

data diff;

set penality2;
by Number;

days_between = dif(penalty_sas_date);

if first.Number then call missing(days_between);

run; ``````
Discussion stats
• 5 replies
• 631 views
• 4 likes
• 4 in conversation