SAS中文论坛

标题: 求助:查找问题? [打印本页]

作者: shiyiming    时间: 2009-11-28 17:24
标题: 求助:查找问题?
求助:查找问题?
       有两个数据集。
data a (keep=d1-d6);
array hm[8] (1 2 3 4 5 6 7 <!-- s8) --><img src="{SMILIES_PATH}/icon_cool.gif" alt="8)" title="Cool" /><!-- s8) -->;
do i1=1 to dim(hm); d1=hm{i1};
do i2=i1+1 to dim(hm); d2=hm{i2};
do i3=i2+1 to dim(hm); d3=hm{i3};
do i4=i3+1 to dim(hm); d4=hm{i4};
do i5=i4+1 to dim(hm); d5=hm{i5};
do i6=i5+1 to dim(hm); d6=hm{i6};
output;
end; end; end; end; end; end;
run;

data b;
input x d1 d2 d3 d4;
cards;
1 2 3 7 8
2 3 4 5 7
;
run;

问题:
在数据集a的每一行观察中,查找是否包含有数据集b的d1 d2 d3 d4的观察,如果有则标出数据集b的序号 xh。

也就是,在数据集a中,查找是否有数据集b的2 3 7 8(顺序不限),只要数据集a的一行观察中有这4个数,就标出数据集b的序号 1。

谢谢!!
作者: shiyiming    时间: 2009-11-29 12:14
标题: Re: 求助:查找问题?
先扔块砖,开始想用SQL的,但没能实现
[code:m8jl25ls]data a (keep=d1-d6);
        array hm&#91;8&#93; (1 2 3 4 5 6 7 8);
        do i1=1 to dim(hm); d1=hm{i1};
        do i2=i1+1 to dim(hm); d2=hm{i2};
        do i3=i2+1 to dim(hm); d3=hm{i3};
        do i4=i3+1 to dim(hm); d4=hm{i4};
        do i5=i4+1 to dim(hm); d5=hm{i5};
        do i6=i5+1 to dim(hm); d6=hm{i6};
        output;
        end; end; end; end; end; end;
run;

data b;
        input x d1 d2 d3 d4;
cards;
1 2 3 7 8
2 3 4 5 7
;

data b_temp;
        set b end=eof;
        string=catx(' ',of d&#58;);
        if eof then call symputx('n',_n_);
run;

proc transpose data=b_temp out=b_temp(keep=p&#58;) prefix=p;
        var string;
run;

data c(keep=d&#58; xh);
        length xh $10;
        set a;
        if _n_=1 then set b_temp;
        string=catx(' ',of d1-d6);
        array flag{&amp;n} $ f1-f&amp;n;
        array parameter{&amp;n} p1-p&amp;n;
        do i=1 to &amp;n;
                if not verify(parameter(i),string) then flag(i)=put(i,best8&#46;);
        end;
        xh=catx(',',of flag(*));
run;[/code:m8jl25ls]




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2