Hash object find method issue?

Frequent Contributor
Posts: 75

Hash object find method issue?

On running the below program, Why is the B_ID column in the results dataset has missing values when it is supposed to be 5. The result other than this issue is correct. Please help fix the problem. Thanks

data in;
input B_ID $ Client_name & $20. Client_Id $;
2             carlsberg            A146
7             kronenbourg        b123
5             stella artois         c987
23           tuborg                 g143
45           budweiser            h765
73           Miller                   b876
data in2;
input (BV_id  Var1 Var2 Var3  Var4 Var5) ($);
5      x      y     z       23    25
5      a      b     c       45    24
5      j       k     l        34    65

data results;
if 0 then set in;
if _N_ = 1 then do;
declare hash h(dataset:'in');
h.defineData('client_name', 'client_id');
set in2;
if h.find(key:BV_id) = 0 then

Super Contributor
Posts: 290

Re: Hash object find method issue?

It is simple. The Key variable will not appear in the output. Only variables that are placed in the data part of the hash will be output. If you want B_ID in the output, add this variable to the data part also like:

h.defineData('B_ID', 'client_name', 'client_id');

Super Contributor
Posts: 308

Re: Hash object find method issue?


B_ID is missing because you don't bring its values to the dataset - results. You only bring from dataset in the variables Client_name and client_id as per h.defineData('client_name', 'client_id');.

if you want the values of B_ID adjust the defineData - h.defineData('client_name', 'client_id', 'b_id'); or h.defineData(all:'YES');

Frequent Contributor
Posts: 75

Re: Hash object find method issue?

Oh yes, Thank you both. I can't believe i missed that simple concept. Anyways my bad. Thank you for the prompt response

Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation