SAS Create a sequence of numbers based on a variable by group

Thanks K,

data test;
input x1 x2;
cards;
1 21
1 21
1 35
2 16
2 22
2 22
;

run;

data test2;
set test;
by x1 x2;
if first.x1 then new=0;
if first.x2 then new+1;
proc print;
run;

/* results */

Obs x1 x2 new

1 1 21 1

2 1 21 1

3 1 35 2

4 2 16 1

5 2 22 2

6 2 22 2

Leave a Reply