11-21-2016 07:43 AM
Not sure what your question here is. You have one variable and need to create another variable which is exactly the same as the variable you have? Maybe your required output is not correct, and you need the sequence within each by group? If so:
data want; set have; do seq_num=1 to 4; output; end; run;
11-21-2016 08:01 AM
I think what you really want is to track the order in which id's first appear, yes? I.e.if you have
then do you wnat id=AAA seq=1, id=A21 seq=2, id=BBB seq=3, id=CCC seq=4.
If so then this would work:
data want (drop=rc); set have; if _n_=1 then do; declare hash id_lookup(); id_lookup.definekey('id'); id_lookup.definedata('seq'); id_lookup.definedone(); end; rc=id_lookup.find(); if rc^=0 then do; seq=id_lookup.num_items+1; rc=id_lookup.add(); end; run;
11-21-2016 10:33 AM
Here's an idea:
seq_num + 1;
if student_id < lag(student_id) then seq_num=1;
It's not 100% clear when to start the SEQ_NUM values over again, but this might be sufficient.
11-21-2016 10:49 AM
I think the OP wants to set up a lookup table, in which each ID is assigned a unique sequence number, with this additional propert: the sequence number will rank the order of first appearance of the ID.