Hash SAS proc sql左连接到哈希对象

Hash SAS proc sql左连接到哈希对象,hash,sas,Hash,Sas,我不熟悉散列对象,但我想了解更多关于它们的信息。我正试图找到用散列对象替代procsql的方法。我必须有两个表,当我有一个带内部连接的proc-sql和一个带equal-with-hash对象时,它可以工作,但当我有一个带left-join的proc-sql时,我不知道如何在hash对象中创建。非常感谢。对不起,我的英语太差了 表01 data Principal; input idd $ name $ Apellid1 $ valor $; datalines; 1977

我不熟悉散列对象,但我想了解更多关于它们的信息。我正试图找到用散列对象替代procsql的方法。我必须有两个表,当我有一个带内部连接的proc-sql和一个带equal-with-hash对象时,它可以工作,但当我有一个带left-join的proc-sql时,我不知道如何在hash对象中创建。非常感谢。对不起,我的英语太差了

表01

data Principal;
   input idd $ name $ Apellid1 $ valor $;
   datalines;
    1977 Arthur Pendrag 0001
    1978 Minerva  Athena 0001
    2011 Noe Arca 0001
    2014 Thor Hammer 0001
    0001 Seiya Pegaso 0001
    0002 Ikki Fenix 0001
    0003 Shun Andromeda 0001
    0004 Shiryu Dragon 0001
    0005 Yoga Cisne 0001
    0006 Naruto Konoha 0001
    0007 Sasuke Kun 0001
;
表02

data Secundarea;
   input idd $ Apellid2 $ mival $;
   datalines;
    1977 Excalibu 0003
    1978 Atenea 0004
    2011 Biblia 0005
    2014 Odin 0006
    0001 Sagigario 0007
    0002 Virgo 0008
    0003 Piscis 0009
    0004 Libra 0010
    0005 Acuario 0011
    0008 Aries 0012
;
Proc sql内部联接

proc-sql;
将表sqlinner创建为
挑选*
从主体作为p内部连接到次区域作为s
p.idd=s.idd;
退出
哈希对象(内部联接)是否有效

过程sql(左连接)

proc-sql;
将表sqlleft创建为
挑选*
从主体作为p左连接到辅助区域作为s
p.idd=s.idd;
退出
如何在散列对象中创建?我在尝试两种方法

data mihashLeft2;
declare hash h();
h.defineKey('IDD');
h.defineData ('IDD','APELLID2','MIVAL');
h.defineDone();
do until(fin1);
    set SECUNDAREA  end=fin1;
    h.add();
end;
do until (fin2);
    set PRINCIPAL end=fin2;
        rc=h.find();
    output;
end;

run;
或者这个。但什么都没有。Thx

data mihashLeft;
if 0 then set SECUNDAREA;
if _n_ =1 then do;
    declare hash hhh(dataset: 'SECUNDAREA', multidata:'y');
    hhh.DefineKey('IDD');
    hhh.DefineData('IDD','APELLID2','MIVAL');
    hhh.DefineDone();
   
    set PRINCIPAL;
    rc = hhh.find();
        if rc ne 0 then do;
            call missing(MIVAL);
            output;
        end;
        else
        do while(rc = 0);
            output;
            rc = hhh.find_next();
        end;
        end;
        run;

您可以尝试这样做:

data mihashLeft(drop=rc);
/*iterate left data set*/
set PRINCIPAL;
/*declare variables from hash set*/
length APELLID2 MIVAL $8 rc 8;
/*declare hash*/
if _n_=1 then do;
    declare hash hhh(dataset: 'SECUNDAREA', multidata:'y');
    hhh.DefineKey('IDD');
    hhh.DefineData('APELLID2','MIVAL');
    hhh.DefineDone();
end;
/*look for first row from hash set and output it even if it's not found*/
rc = hhh.find();
output;
/*loop to find other rows from the hash set*/
do while(rc=0);
    rc = hhh.find_next();
    /*output only if you found something*/
    if rc=0 then output;
end;
运行

data mihashLeft(drop=rc);
/*iterate left data set*/
set PRINCIPAL;
/*declare variables from hash set*/
length APELLID2 MIVAL $8 rc 8;
/*declare hash*/
if _n_=1 then do;
    declare hash hhh(dataset: 'SECUNDAREA', multidata:'y');
    hhh.DefineKey('IDD');
    hhh.DefineData('APELLID2','MIVAL');
    hhh.DefineDone();
end;
/*look for first row from hash set and output it even if it's not found*/
rc = hhh.find();
output;
/*loop to find other rows from the hash set*/
do while(rc=0);
    rc = hhh.find_next();
    /*output only if you found something*/
    if rc=0 then output;
end;
data mihashLeft;

set PRINCIPAL;   /* left */

 if _n_ = 1 then do;
 if 0 then set SECUNDAREA;
 dcl hash b (dataset: "SECUNDAREA", multidata: "y",ordered:'y');

 b.definekey ("IDD");
 b.definedata (all:'Y');
 b.definedone ();

 end;

 if b.find() eq 0 then output;

/*if b.find() ne 0 then call missing(right_table_column);*/
/*if suppose you are pulling any column from right table then include above line*/

run;