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 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 394 views
  • 0 likes
  • 2 in conversation