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;
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;
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.
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;
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
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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.