data a;
if _n_<11 then g=1;else g=2;
input x $ @@;
y=dif(x);
cards;
07 08 09 12 13 14 15 19 21 22 23 24 29 30 31 32 36
;run;
data c;
length result $100;
retain result;
flag=0;
do until(y>1 or last.g);
set a;
by g x;
if first.g then result=x;
if y=1 then do;flag=1; tmp=x;end;
end;
if flag=1 then do;
result=catx("-",result,tmp);
if not last.g or y>1 then result=catx(", ",result,x);
end;
else result=catx(", ",result,x);
if last.g then output;
keep g result;
run;