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;
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
  • 383 views
  • 1 like
  • 2 in conversation