input city :$20. Q1 Q2;
datalines;
Zhejiang . .
HZ 10 11
NB 20 12
LS 12 13
. 42 36
Beijing . .
HD 20 14
CW 30 15
CP 40 21
. 90 50
;
run;
data temp;
set test;
retain cityx;
if Q1=. then cityx=city;
run;
data want(drop=cityx);
set temp;
if q1=. then delete;
if city="" then city=cityx;
run;
优点是可以自动识别beijing等地名,地名下面数据部分的行数可以不固定
运行结果: