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

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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