Hello
I want to create seq number that each group get different seq number (but all rows in same group get same seq number)
what is the way to create want data set please?
data have;
format ddate ddmmyy10.;
input custid ddate: date9. x;
cards;
111 01apr2025 10
111 02apr2025 20
111 03apr2025 30
222 01apr2025 40
222 02apr2025 50
333 01apr2025 60
;
run;
data want;
format ddate ddmmyy10.;
input custid ddate: date9. x seq;
cards;
111 01apr2025 10 1
111 02apr2025 20 1
111 03apr2025 30 1
222 01apr2025 40 2
222 02apr2025 50 2
333 01apr2025 60 3
;
run;
Oki I found the solution
data want;
set have;
BY custid ddate;
RETAIN seq 0;
IF First.custid THEN seq +1;
Run;
If you use syntax like seq + 1 left of/without an equal sign then the variable will get retained. For this reason retain seq 0 is not necessary (also not wrong though and doesn't hurt for additional clarity).
Yes - in this case, you can also just do:
data want;
set have;
by custid;
seq+first.custid;
run;
@quickbluefish wrote:
Yes - in this case, you can also just do:
data want; set have; by custid; seq+first.custid; run;
Kudos for brevity. I love tight code.
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.