BookmarkSubscribeRSS Feed
MarkWik
Quartz | Level 8

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 $;
datalines;
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) ($);
datalines;
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.defineKey('b_id');
h.defineData('client_name', 'client_id');
h.defineDone();
end;
set in2;
if h.find(key:BV_id) = 0 then
output;
run;

3 REPLIES 3
KachiM
Rhodochrosite | Level 12

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');

Loko
Barite | Level 11

Hello,

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');

MarkWik
Quartz | Level 8

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1032 views
  • 6 likes
  • 3 in conversation