BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
1 REPLY 1
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 686 views
  • 0 likes
  • 2 in conversation