Hi,
I am not really sure how to explain this or what term to use so excuse me on the subject so i have this sample dataset below that i need to assign an incremental field (GROUP_ID), for every time it sees a 'B' status GROUP_ID ill have a +1 please see expected result for more info.
**sample data
ROW_NUM STATUS
1 A
2 A
3 B
4 A
5 A
6 A
7 B
8 A
9 A
10 B
**expected result
ROW_NUM STATUS GROUP_ID
1 A 1
2 A 1
3 B 1
4 A 2
5 A 2
6 A 2
7 B 2
8 A 3
9 A 3
10 B 3
cheers guys.
No need for excuses. You give us sample data, an explanation and and example of how the desired result should look like. That's all that's normally required to understand.
data have;
input ROW_NUM STATUS $;
datalines;
1 A
2 A
3 B
4 A
5 A
6 A
7 B
8 A
9 A
10 B
;
run;
data want;
set have;
by STATUS notsorted;
if _n_=1 then group_id=1;
else if first.status and status='A' then group_id+1;
run;
No need for excuses. You give us sample data, an explanation and and example of how the desired result should look like. That's all that's normally required to understand.
data have;
input ROW_NUM STATUS $;
datalines;
1 A
2 A
3 B
4 A
5 A
6 A
7 B
8 A
9 A
10 B
;
run;
data want;
set have;
by STATUS notsorted;
if _n_=1 then group_id=1;
else if first.status and status='A' then group_id+1;
run;
That was fast, thank you so much mate! it worked :smileygrin:
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.