Yes, there is a better way I think, in fact two better ways. First, I would use only one function, copying and pasting 11 functions is awful especially when you want to change something afterwards.

function assign_units()
{
var unit_number;
if (key_1) unit_number = 1;
else if (key_2) unit_number = 2;
... etc.
and then use the unit_number var in your function to assign the group to.

and assign the same function to all 11 keys:

...
on_1 = assign_units;
on_2 = assign_units;
... etc.

Second, your code is very slow due to the wait()

you = ent_next(you); //find the next entity
wait(1); //avoid endless loops

but there is no endless loop, an endless loop would begin with while(1). So without the unnecessary wait your function will run much faster.