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*/
data want;
set ttt;
by branch;
if first.branch then seq + 1; /* sum statement implies retain */
run;
Untested, posted from my tablet.
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?
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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.