Hello
I want to create serial number within each group by following rule:
Wanted calculate column is called seq.
How can I calculate it please from have data set?
The rule is - for each group we calculate seq numbers but IF values of X,Z are same between rows then rows get same seq number
data have;
input group x z seq;
cards;
111 10 20 1
111 10 20 1
111 30 40 2
222 10 20 1
222 10 20 1
333 40 50 1
444 15 20 1
444 15 20 1
444 15 20 1
444 30 50 2
444 60 80 3
444 60 80 3
;
Run;
data have;
input group x z seq;
cards;
111 10 20 1
111 10 20 1
111 30 40 2
222 10 20 1
222 10 20 1
333 40 50 1
444 15 20 1
444 15 20 1
444 15 20 1
444 30 50 2
444 60 80 3
444 60 80 3
;
Run;
data want;
set have;
by group x z notsorted;
if first.group then want_seq=0;
want_seq+first.z;
run;
data have;
input group x z seq;
cards;
111 10 20 1
111 10 20 1
111 30 40 2
222 10 20 1
222 10 20 1
333 40 50 1
444 15 20 1
444 15 20 1
444 15 20 1
444 30 50 2
444 60 80 3
444 60 80 3
;
Run;
data want;
set have;
by group x z notsorted;
if first.group then want_seq=0;
want_seq+first.z;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.
Ready to level-up your skills? Choose your own adventure.