How to sort the atoms in the order when I use write_data command

How to sort the atoms in the order when I use write_data command?

You cannot. You would have to post-process the file.

Not sure what the use case is but you can sort atoms for write_dump instead, see dump_modify command — LAMMPS documentation.