BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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;
4 REPLIES 4
Ronein
Meteorite | Level 14

Oki I found the solution

 


data want;
set have;
BY custid ddate;
RETAIN seq 0;
IF First.custid THEN seq +1;
Run;
Patrick
Opal | Level 21

@Ronein 

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).

quickbluefish
Barite | Level 11

Yes - in this case, you can also just do:

data want;
set have;
by custid;
seq+first.custid;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 4 replies
  • 574 views
  • 5 likes
  • 4 in conversation