data sample;
input date $ number $14.;
cards;
20031101 75582368888
20031101 2082368887
20031102 2182368886
20031102 5236237888
;
run;
data temp;
set sample;
numlength= length(number);
if numlength = 10 then
do;
if substr(number,1,2)='20' then /*本例中只有2个这类城市,如果10个都包含的话,这一段程序会比较复杂*/
do;
area='Guangzhou';
end;
else if substr(number,1,2)='21' then
do;
area='Shanghai';
end;
else do;
area= substr(number,1,3);
end;
end;
if numlength = 11 then area= substr(number,1,3);
run;
data temp;
set sample;
if substr(number,1,2) in ('10','20','21','22','23',
'24','25','26','27','28','29') then area= substr(number,1,2);
else area= substr(number,1,3);
run;