Search code examples
sasproc-sql

create unique id variable based on existing id variable


Trying to make a more simple unique identifier from already existing identifier. Starting with just and ID column I want to make a new, more simple, id column so the final data looks like what follows. There are 1million + id's, so it isnt an option to do if thens, maybe a do statement?

ID NEWid

1234 1

3456 2

1234 1

6789 3

1234 1


Solution

  • A trivial data step solution not using monotonic().

    proc sort data=have;
    by id;
    run;
    
    data want;
    set have;
    by id;
    if first.id then newid+1;
    run;