Hi, I seem to be getting an error in the calculation of the number of days between two dates. For example, in my dataset, I have 20130220 and 20130415 and using the INTCK Function, I am getting -596 where it should be 55. Not too sure why or where the negative number is coming from. Thanks in advance.
DATA SUMMARY;
SET SUMMARY;
IF (ID = LAG(ID)) AND (CLAIM_DATE >= LAG(CLAIM_DATE)) THEN DO;
DIFF = INTCK('DAY',INPUT(PUT(LAG(CLAIM_DATE),8.),yymmdd8.),INPUT(PUT(CLAIM_DATE,8.),yymmdd8.))+1;
END;
RUN;
Could you provide some test data there. Not sure why you are putting lag(claim_date) to number then reading in as date.
Try to isolate your problem, i.e. separating your LAG(), input() and intck() into separate statements.
Use put _ALL_ to monitor the results of your operations.
But I have never really understood the value of using INTCK without arguments for straight dates. You just use simple subtraction on SAS dates....?
hello,
probably it is because of LAG(CLAIM_DATE), executed conditionally. if sometimes the condition is not true the results are not the expected ones.
Hi.....here is some output when I ran the code.
ID | CLAIM_DATE | DIFF |
100003976 | 20130709 | |
100003976 | 20130808 | 37 |
100003976 | 20130909 | 33 |
100003976 | 20131007 | 29 |
100003976 | 20131104 | 29 |
100003976 | 20131114 | 11 |
100004028 | 20130220 | |
100004028 | 20130415 | -596 |
100004028 | 20130622 | 69 |
100004028 | 20130819 | 59 |
100004028 | 20131016 | 59 |
100004028 | 20131231 | 77 |
100004028 | 20140224 | 56 |
100009987 | 20120222 | |
100009987 | 20120319 | -951 |
100009987 | 20120420 | 33 |
100009987 | 20120519 | 30 |
100009987 | 20120618 | 31 |
100009987 | 20120917 | 92 |
100009987 | 20121219 | 94 |
100009987 | 20130328 | 100 |
Thanks everyone. Apparently, it looks like the INTCK Function does not like the LAG Function as part of the Start or End Date. I created another variable for the Lag claim date and then used the new variable with the INTCK Function and it seems to work fine now.....Thanks Once Again.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.