I have the following code which I need to decode and will require the communities help to understand if my thinking is correct. Here's the code:
data facilities(index=(obk fack))
f_xclud
;
format arrival_dt_system last_dt date9.;
length cd_base_id $6. cm_ind_l2 $25.;
if _n_ eq 1 then do;
declare hash nai (dataset:"D_industry");
nai.definekey ('ind_gen_id');
nai.definedata ('cd_base_id','cm_ind_l2');
nai.definedone ();
call missing(cd_base_id, cm_ind_l2);
declare hash arv (dataset:"f_a_dt");
arv.definekey ('ps_o_id', 'ps_s_id ', 'ps_f_id');
arv.definedata ('arrival_dt_system', 'last_dt');
arv.definedone ();
call missing(arrival_dt_system, last_dt);
end;
merge
facs_sorted(in=from1)
f_lg_v(in=from2)
f_xclud(in=from3)
defaults(in=from4)
end = last_obs;
by ps_o_id ps_s_id ps_f_id period_dt;
rc = arv.find();
rc = nai.find();
drop rc;
if pd_e_flag EQ 'Y' then output f_xclud;
else output facilities;
run;
My understanding:
Its Creating a merged dataset from the 4 tables:
facs_sorted(in=from1)
f_lg_v(in=from2)
f_xclud(in=from3)
defaults(in=from4)
usinf the variables mentioned after "BY"
Then its left joining the merged table with the dataset mentioned under the two hash object with their respective keys.
Finally its storing the output table based on the variable pd_e_flag and its value,
Please let me know if I am missing anything. TIA
You are right. The two hash objects perform a lookup without the need for additional sorting of the base datasets (the result of the 4-way merge).
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.