流水不朽 发表于 2016-9-24 16:14
给种简单的方法
假设tmp 数据集除了 结果变量result 外的数据集
data tmp_01(keep=num name col_w)
我将原始数据代入,好像跑不出来结果啊,烦请您帮我看看,可以吗?
data tmp;
infile cards missover;
input @1 name $ col_2010 $ col_2011 $ col_2012 $ col_2013 $ ;
cards;
邹** A车间 A车间 A车间
林** C车间 C车间 C车间 C车间
林** C车间 C车间 D车间 C车间
林** C车间 C车间 C车间 C车间
戴** B车间
王** B车间
王* B车间 B车间 B车间 B车间
高* F车间 E车间
江** E车间 E车间 E车间
钱* F车间
张* E车间 E车间
廖* F车间 A车间
廖*1 A车间 A车间 H车间
李* E车间 G车间 A车间 A车间
王* E车间 E车间 I车间
臧* E车间 E车间 E车间
;
data tmp_01(keep=num name col_w)
tmp(keep=num name col_2010-col_2013)
;
set tmp;
format col_ $40.;
col_=catx(',',col_2010,col_2011,col_2012,col_2013);
n=countw(col_,',');
num=put(_n_,z2.);
do i=1 to n by 1;
col_w=scan(col_,i,col_);
end;
run;
proc sort data=tmp_01 nodupkey;by num name col_w;run;
data tmp_02;
set tmp_01;
by num name col_w;
retain result;
if first.num then
result=1;
else result=result+1;
if last.num;
run;
proc sql;
create table result_ as
select a.*
,b.result
from tmp a
left outer join
tmp_02 b
on a.num=b.num
;
quit;