derive_seq function

Derive the sequence number (--SEQ) variable