Help using Base SAS procedures

Looking ahead with a Data Step

Reply
N/A
Posts: 0

Looking ahead with a Data Step

I'm hoping someone can help me with the following:

The following is my dataset:

MKT RB_FLAG DATE1 DATE2
A RB 19SEP 17OCT
A NRB 19SEP 24OCT
A RB 19SEP 21NOV
B NRB 17OCT 17OCT
B RB 17OCT 24OCT
B RB 17OCT 14NOV
B NRB 17OCT 29DEC
B RB 17OCT 16JAN
B NRB 17OCT 23JAN

For each MKT I need to take the first instance when RB_FLAG="RB" and the first instance after where RB_FLAG="NRB" then calculate the difference between DATE1 (for RB) and DATE2 (for NRB). Also, I'm only interested in the first occurence of RB within a MKT. Ultimately, I'm trying to arrive at the following table:

MKT RB_FLAG DATE1 DATE2 WEEK_DIFF
A RB 19SEP 24OCT 5
B RB 17OCT 19DEC 10

I have read some similar posts on "looking ahead" within a datastep but I'm struggling to adapt the suggestions to my problem.

Thank you ahead of time for you help on this!
Rich
Super Contributor
Super Contributor
Posts: 3,174

Re: Looking ahead with a Data Step

Investigate using BY GROUP processing within the DATA step and you will want to use RETAIN to track your DATE1 value across DATA step iterations.

Scott Barry
SBBWorks, Inc.

Recommended Google advanced search argument for this topic/post:

data step by group processing site:sas.com
Ask a Question
Discussion stats
  • 1 reply
  • 102 views
  • 0 likes
  • 2 in conversation