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');
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.