BookmarkSubscribeRSS Feed
Kanyange
Fluorite | Level 6

Hi All,

 

I have aroound 10,000 customers who switched from one product_id to another. I would like to identify when is the Yearmonth when the Target_field changes from 1 to 0. I am interested to see what was the yearmonth they went from 1 to 0. But not from 0 to 1. Below is an example of how my current data looks like per customer. This customers started with Target_field=1 and he switched to 0 in Year=201406.

 

Your Help would be much appreciated.

 

Thank You

 

id     prod_id Year Target_field
19081 2338 201402 1
19081 2338 201403 1
19081 2338 201404 1
19081 2338 201405 1
19081 2486 201406 0
19081 2486 201407 0
19081 2486 201408 0
19081 2486 201409 0
19081 2486 201410 0
19081 2486 201411 0
19081 2486 201412 0
19081 2486 201501 0
19081 2486 201502 0
19081 2486 201503 0
19081 2486 201504 0
19081 2486 201505 0
19081 2486 201506 0
19081 2486 201507 0
19081 2486 201508 0

 

 

 

 

 

 

2 REPLIES 2
LinusH
Tourmaline | Level 20
Use a data step using BY and first./last. processing with RETAIN.
Data never sleeps
PGStats
Opal | Level 21

Simple BY processing can do this

 


data switches;
set have; by id target_field notsorted;
if 
    first.target_field and 
    not first.id and 
    target_field=0 then output;
run;
PG

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 1153 views
  • 0 likes
  • 3 in conversation