The Density statement does not support GROUP role. In cases where you have a known number of group values, you could transpose your data into multiple columns and overlay the needed plots as shown below. You don't need the BY statement.
data density;
drop i;
do i=1 to 100;
A = 20+20*ranuni(2);
B = 20+30*ranuni(3);
output;
end;
run;
/*proc print;run;*/
proc sgplot data=density;
density a / legendlabel='A';
density b / legendlabel='B';
run;