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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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