BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasphd
Lapis Lazuli | Level 10

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
Reeza
Super User

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; 

View solution in original post

5 REPLIES 5
japelin
Rhodochrosite | Level 12
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?
Kurt_Bremser
Super User

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.

Reeza
Super User

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;


 

sasphd
Lapis Lazuli | Level 10

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

sasphd_0-1642106076494.png

 

Reeza
Super User

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; 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 631 views
  • 4 likes
  • 4 in conversation