Suppose I have a list of things (numbers, to keep things simple here) and I have a function I want to use to sort them by, using SortBy. For example, the following sorts a list
Does GatherBy do what you want?
Flatten[GatherBy[{301, 201, 502, 501, 101}, Mod[#, 10] &]]