SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
rahulsaha2127
Fluorite | Level 6

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

1 REPLY 1
Kurt_Bremser
Super User

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).

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 1 reply
  • 685 views
  • 0 likes
  • 2 in conversation