data _null_;
set a;
where name="haha";
call symput("obs",obs);
run;
%let obs1=%eval(&obs-1);
%let obs2=%=%eval(&obs+1);
data b;
set a;
where obs in(&obs1,&obs,&obs2);
run;
data want(keep=obs name);
set have_tr;
array d(*)_1-_9;
do i=1 to dim(d);
if d(i)="haha" then do;
if i ne 1 then do;
obs=i-1;
name=d(i-1);
output;
end;
obs=i;
name=d(i);
output;
if i ne dim(d) then do;
obs=i+1;
name=d(i+1);
output;
end;
end;
end;
run;
最后的名为want的数据集便是所需要的