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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.