DATA Step, Macro, Functions and more

re: Counting Number of Days Error

Reply
Regular Contributor
Posts: 229

re: Counting Number of Days Error

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;

Super User
Super User
Posts: 7,981

Re: re: Counting Number of Days Error

Could you provide some test data there.  Not sure why you are putting lag(claim_date) to number then reading in as date. 

Super User
Posts: 5,437

Re: re: Counting Number of Days Error

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....?

Data never sleeps
Super Contributor
Posts: 308

Re: re: Counting Number of Days Error

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.

Regular Contributor
Posts: 229

Re: re: Counting Number of Days Error

Hi.....here is some output when I ran the code.

IDCLAIM_DATEDIFF
10000397620130709
1000039762013080837
1000039762013090933
1000039762013100729
1000039762013110429
1000039762013111411
10000402820130220
10000402820130415-596
1000040282013062269
1000040282013081959
1000040282013101659
1000040282013123177
1000040282014022456
10000998720120222
10000998720120319-951
1000099872012042033
1000099872012051930
1000099872012061831
1000099872012091792
1000099872012121994
10000998720130328100
Regular Contributor
Posts: 229

Re: re: Counting Number of Days Error

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.

Ask a Question
Discussion stats
  • 5 replies
  • 247 views
  • 8 likes
  • 4 in conversation