Hi,
I have to create flags 1/0 for codes based on +/-3 weeks for a given ID and date.
For example for
ID abc and date 1/1/2014-- I need to check if there is any code present in +/-3 days and based on that I have to create flags for ABC. I have attached sample output.
I am not sure what approach to use in this case.
Input
ID | Date | Date 2 | Code |
abc | 1/1/2014 | ||
abc | 1/2/2014 | ||
abc | 1/3/2014 | ||
abc | 1/4/2014 | ||
abc | 1/5/2014 | ||
abc | 1/6/2014 | 1/6/2014 | A |
abc | 1/7/2014 | ||
abc | 1/8/2014 | ||
abc | 1/9/2014 | ||
abc | 1/10/2014 | 1/12/2014 | B |
abc | 1/11/2014 | ||
abc | 1/12/2014 | ||
abc | 1/13/2014 | ||
abc | 1/14/2014 | ||
abc | 1/15/2014 | ||
abc | 1/16/2014 | ||
abc | 1/17/2014 | ||
abc | 1/18/2014 | 1/18/2014 | C |
abc | 1/19/2014 | ||
abc | 1/20/2014 | ||
abc | 1/21/2014 | ||
abc | 1/22/2014 | ||
abc | 1/23/2014 | ||
abc | 1/24/2014 | ||
abc | 1/25/2014 | ||
abc | 1/26/2014 | ||
abc | 1/27/2014 | ||
abc | 1/28/2014 | ||
abc | 1/29/2014 | ||
abc | 1/30/2014 | ||
abc | 1/31/2014 |
Sample Output
ID | Date | A | B | C |
abc | 1/1/2014 | 0 | 0 | 0 |
abc | 1/2/2014 | 0 | 0 | 0 |
abc | 1/3/2014 | 1 | 0 | 0 |
abc | 1/4/2014 | |||
abc | 1/5/2014 | |||
abc | 1/6/2014 | |||
abc | 1/7/2014 | 1 | 1 | 0 |
Solved! Go to Solution.
Here's a summary of how I approached this:
- Data prep by formatting the "Date" field as a date field type so datetime formulas could be used.
- Created a list of days that each code should apply to (3 days before/after each code)
- Joined those created code days to the original file and summarized.
You mentioned both weeks and days in your example. I used days in my solution, but it is easily edited to work for weeks. Solution attached.