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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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