I have two columns like, treatcode and groups
If treatcode is 2 (A,B) then groups column should be
AB, BA
If treatcode is 3 (A,B,C) then groups column shoud be
ABC
BCA
CAB
CBA
BAC
ACB

If treatcode is 4 (A,B,C,D) then groups column shoud be
ABCD
BCDA
CDAB
DABC
........

Whenever the treatcode increases the groups should be increase.
Please let me know is there any good approach for this?

Thanks
malli