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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 945 views
  • 0 likes
  • 2 in conversation