Try to search your question here, if you can't find : Ask Any Question Now ?

finding days between depending on various conditions by not using coalease function

HomeCategory: stackoverflowfinding days between depending on various conditions by not using coalease function
Avatarwillson asked 4 months ago

Lets say the data is like this

cust_id visit_dt    Purchase_dt item    FIRST_Purchase_dt       
1234    1/11/2017   1/12/2017   Big     1/1/2015            
1234    1/18/2018   1/19/2018   Big     1/1/2015                     
1567    1/11/2008   1/12/2008   Big     3/27/2007                    
1345    1/3/2006                Small   1/2/2006                     
1345    1/24/2008   1/24/2008   Big     1/2/2006                     
1579    1/24/2009               Medium  5/6/2006    

I want to calculate days between like calculation enter image description here
Days between should be calculated like this-

a) if there is no duplicate Cust_id then it is visit_dt-First_Purchase dt or the first duplicate cust_id when sorted by visit_dt.

b) if there is duplicate then visit_dt-Previous(purchase_dt) if it exists else visit_dt-previous(visit_dt).
This happens as when the item is small or medium then there is no purchase dt. Note I am not looking for coalease function as I might implement it in SAS too which lacks this function.

 select  cust_id,visit_dt,Purchase_dt, item,FIRST_Purchase_dt,visit_dt-FIRST_Purchase_dt as Days_BTW 

this works only for first condition not sure how to implement the second condition

1 Answers
Best Answer
AvatarMatthias answered 4 months ago
Your Answer

16 + 11 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com