Perhaps you can do something like this:
1) Sort by Group, Company
2) Create a group signature by concatenating all groups for each company together into a single string. Be sure to also use a delimiter.
3) Create a distinct list of the signatures and assign an ID to each.
4) Match the ID back against the data from step 2.\
data x;
attrib group format=best.
company length=$1;
input group $ company;
datalines;
1 A
1 B
1 C
2 A
2 Z
3 A
3 B
3 C
4 B
;
run;
proc sort data=x;
by group company;
run;
data x2;
attrib sig length=$100;
set x;
by group;
retain sig;
if first.group then do;
sig = company;
end;
else do;
sig = catx('#',sig,company);
end;
if last.group then do;
output;
end;
run;
proc sort data=x2 out=sigs nodupkey;
by sig;
run;
data sigs2;
set sigs;
id = catt("id",_n_);
run;
proc sql noprint;
create table final as
select a.*,
c.id
from x a
join x2 b on b.group eq a.group
join sigs2 c on c.sig eq b.sig
order by group, company
;
quit;
Cheers
Rob