Something like this should work. May not be exactly what you are looking for, but let me know.
/* Create data as an example for this */
data temp;
infile datalines dsd delimiter=',';
attrib charcol1 length = $1
charcol2 length = $1;
input charcol1 $
charcol2 $;
datalines;
A,A
A,B
A,
A,C
A,D
;
run;
/* Pre-sort the data by the variable in question, very important */
proc sort data=temp out=tempsort;
by charcol1 charcol2;
run;
/* Use a BY statement for the sorted variable */
data temp2;
set tempsort;
retain charcol1 charcol2;
by charcol1 charcol2;
if first.charcol1 then id+1;
if first.charcol2 and charcol2 NE ' ' then id2+1;
if id2=0 then id2=.;
run;
A 1 .
A A 1 1
A B 1 2
A C 1 3
A D 1 4