BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bnarang
Calcite | Level 5

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

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

2 REPLIES 2
Astounding
PROC Star

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;

bnarang
Calcite | Level 5

Thanks. The solution has worked.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 1444 views
  • 0 likes
  • 2 in conversation