12、13、14、15第一位一样的视为一组
如果一组的B值都为1则合并信息,不为1置为空
结果如下:
A B
1
2 1
3 1
4作者: shiyiming 时间: 2012-5-27 11:54 标题: Re: 数据合并问题 如果a是111,该怎么取? 是1还是11?
[code:1lhp3jit]data raw;
infile datalines missover;
input A B;
datalines;
12 1
13
14 1
15 1
21 1
22 1
23 1
24 1
31 1
32 1
41 1
42
43 1
;
data _null_;
if _n_=1 then do;
declare hash h(hashexp:4,ordered:'y');
rc=h.defineKey('a');
rc=h.defineData('a','b');
rc=h.defineDone();
end;
set raw end=last;
a=int(a/10); _b=b;
if h.find() ne 0 then rc=h.add();
else if b then rc=h.replace(key:a,data:a,data:_b);
if last then rc=h.output(dataset:'work.out');
run;
[/code:1lhp3jit]作者: shiyiming 时间: 2012-5-29 14:12 标题: Re: 数据合并问题 谢谢回答,对于你的问题,我这边只有11这样的情况,111的情况应该是取11为一组作者: shiyiming 时间: 2012-5-30 03:28 标题: Re: 数据合并问题 [code:2ihmhs3k]
data x;
input A B;
cards;
12 1
13
14 1
15 1
21 1
22 1
23 1
24 1
31 1
32 1
41 1
42
43 1
;
run;
proc sql;
create table y as
select substr(cats(A), 1, 1) as A,
case
when (count(distinct B)=1) then '1'
else ' '
end as B
from x
group by calculated A
;
quit;