BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

1 REPLY 1
Ksharp
Super User
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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 67 views
  • 1 like
  • 2 in conversation