Hi, I have a dataset with customer id, date, and segment. It is sorted by customer id and date because I want to utilize first. to figure out the first date that a customer entered a new segment. A customer can re-enter a segment multiple times and stay there for a few weeks. However, I do not want it to continue counting weeks when they re-enter a segment. I want the counter to start over. Data Set currently looks like this: Customer ID Date Segment 100100 1-Nov-15 Analog 100100 8-Nov-15 Analog 100100 15-Nov-15 Analog 100100 22-Nov-15 Digital 100100 29-Nov-15 Digital 100100 6-Dec-15 Analog 100100 13-Dec-15 Analog Desired Output looks like this: Customer ID Date Segment Segment Date 100100 1-Nov-15 Analog 1 100100 8-Nov-15 Analog 2 100100 15-Nov-15 Analog 3 100100 22-Nov-15 Digital 1 100100 29-Nov-15 Digital 2 100100 6-Dec-15 Analog 1 100100 13-Dec-15 Analog 2 I can get the counter and re-set to work with the code below, but it does not start over from 1 when a customer re-enters a previous segment. Instead, it continues increasing the counter. My code and current output is below: data lastdig0; set lastdig0(drop=segment_weeks); segment_weeks+1; by tid segment; if first.tid or first.segment then segment_weeks=1; run; Customer ID Date Segment Segment Date 100100 22-Nov-15 Digital 1 100100 29-Nov-15 Digital 2 100100 1-Nov-15 Analog 1 100100 8-Nov-15 Analog 2 100100 15-Nov-15 Analog 3 100100 6-Dec-15 Analog 4 100100 13-Dec-15 Analog 5 Any ideas on how to get this to correctly? Thank you!
... View more