look back period: SQL code?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

look back period: SQL code?

All-

 

I am trying to figure out the most efficient way to code for a "clean period," or a 6 month time period in which x=0.

 

there are three variables of interest for each observation

 

trigger date

claim date

x=  0 or 1

 

I'd like to make a new variable that flags the observation if x =1 and the time interval between the trigger date and the claim date is 6 months or less.  INTCK doesn't seem appropriate because neither date is standardized.  someone mentioned that PROC SQL "date matching" may be the right function, but I can't find syntax for that.  any ideas?

 

Thank you!

 


Accepted Solutions
Solution
‎04-04-2017 03:39 PM
Respected Advisor
Posts: 4,606

Re: look back period: SQL code?

I don't know what you mean by standardized date. If your dates are SAS dates, this would work:

 


data want;
set have;
back_pn_6_mo_event = 
    back_pn and 
    intck("MONTH", claim_date, trigger_date, "CONTINUOUS") <= 6 ;
run;

If your dates are not SAS dates, then make them so.

PG

View solution in original post


All Replies
Esteemed Advisor
Posts: 5,194

Re: look back period: SQL code?

If you supply sample input and desired output data it would help to visualize your problem.

Data never sleeps
Occasional Contributor
Posts: 7

Re: look back period: SQL code?

input:

 

trigger-date  claim_date   back_pn

1/13/13   2/13/12   1

1/13/13  4/20/12   0

1/13/13  7/25/12    0

1/13/13 10/15/12  1

2/18/13  8/19/12   0

2/18/13  9/8/12    1

3/12/13 11/30/12 1

3/12/13 12/13/12 1

3/12/13  12/28/12 1

 

output

trigger-date  claim_date   back_pn  back_pn_6_mo_event

1/13/13             2/13/12           1              0

1/13/13              4/20/12           0             0

1/13/13              7/25/12           0             0

1/13/13              0/15/12           1             1

2/18/13              8/19/12           0             0

2/18/13                9/8/12           1              1

3/12/13            11/30/12           1             1

3/12/13             12/13/12          1             1

3/12/13              2/28/12           1             1

 

 

Solution
‎04-04-2017 03:39 PM
Respected Advisor
Posts: 4,606

Re: look back period: SQL code?

I don't know what you mean by standardized date. If your dates are SAS dates, this would work:

 


data want;
set have;
back_pn_6_mo_event = 
    back_pn and 
    intck("MONTH", claim_date, trigger_date, "CONTINUOUS") <= 6 ;
run;

If your dates are not SAS dates, then make them so.

PG
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 142 views
  • 0 likes
  • 3 in conversation