h.find()在查找到key的同时, 会 set data (把data的值取出, 覆盖PDV中相同变量的值)
c=h.check()只查找key的值是否存在,不管data的值.
- /* try this */
- data a;
- input a b $;
- cards;
- 1 q
- 2 w
- 3 e
- 1 r
- 2 t
- ;run;
- data b;
- if 0 then set a;
- if _n_ = 1 then do;
- length new $4.;
- declare hash h(hashexp:4);
- h.definekey('a');
- h.definedata('a','b','new');
- h.definedone();
- call missing(a,b,new);
- end;
- set a end = last;
- c = h.check(); put _all_;
- if c ^= 0 then do; /* c^=0 mean the key not exist in the hash table */
- new = b;
- h.add();
- end;
- else do; /* when _n_ = 4*/
- * new = ; /* value b already saved in hash library:'q'*/
- h.find(); /* assign b with the value in hash table */
- * new = b;
- end;
- run;