Hi
I am trying to work around a certain business problem where I need to flag certain event. I have tried coding but unable to come to any solution being a novice. Any help will be appreciated.
For the simplicity purposes, consider the data below. I have two fields ID and event with ID as identifier and event as specific event either a or b
Value to move and augment in set. for example - for first set of a ( which are 3 obs. for ID1) as 0
Value to change to 1 when event b occurs and remains for set in continuation
Value to change to 2 when event changes again and to a
Value to change to 3 when event change again to b
Value should initialize to 0 post 3 events in event a
Input:
ID event
1 a
1 a
1 a
1 b
1 b
1 a
1 a
1 b
1 a
1 a
2 a
2 b
2 a
2 a
2 b
Output:
ID event Value
1 a 0
1 a 0
1 a 0
1 b 1
1 b 1
1 a 2
1 a 2
1 b 3
1 a 0
1 a 0
2 a 0
2 b 1
2 a 2
2 a 2
2 b 3
Thanks in Advance
Worth trying:
data want;
set have;
by id event notsorted;
if first.id then value=0;
else if first.event then value + 1;
if value=4 then value=0;
run;
Worth trying:
data want;
set have;
by id event notsorted;
if first.id then value=0;
else if first.event then value + 1;
if value=4 then value=0;
run;
Thanks. The solution has worked.
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.