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
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.