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;
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');
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');
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.