BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

What is the way to create a sequence of numbers between groups.

so, for branch 123 will get value 1 ,

for branch 159 will get value 2  

for branch 181 will get value 3  

 

data ttt;
input branch  Y;
datalines;
123 14
123 15
123 16
159 17
159 18
159 19
159 20
159 30
181 30
181 40
181 50 ; run; /*wanted data set*/ /*123 14 1*/ /*123 15 1*/ /*123 16 1*/ /*159 17 2*/ /*159 18 2*/ /*159 19 2*/ /*159 20 2*/ /*159 30 2*/ /*181 40 3*/ /*181 50 3*/
3 REPLIES 3
ballardw
Super User

If you want a repeatable number so the same group always gets the same number create a format that links the branch numbers to a given "sequence" and use the format with the variable.

 

How is the "sequence" number to be used?

PeterClemmensen
Tourmaline | Level 20
data ttt;
input branch Y;
datalines;
123 14
123 15
123 16
159 17
159 18
159 19
159 20
159 30
181 30
181 40
181 50
;

data want;
   set ttt;
   by branch;
   if first.branch then s + 1;
run;

 

Result:

 

branch Y   s 
123    14  1 
123    15  1 
123    16  1 
159    17  2 
159    18  2 
159    19  2 
159    20  2 
159    30  2 
181    30  3 
181    40  3 
181    50  3 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 983 views
  • 0 likes
  • 4 in conversation