BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Myurathan
Quartz | Level 8

Hi Experts,

I want to left join two tables (table A and table B). 

Table A

Date_IDIDFlag
2019020214715Y
2019020314715Y
2019020414715Y
20190202888Y
20190203888Y

 

Table B

Date_IDIDCID
2019020214715222
2019020314715222
2019020414715222
2019020214715333
2019020314715333
2019020414715333
201902021295128444
201902031295128444
201902041295128444

 

Code I'm using

 

data w(drop=rc);
   if _N_ = 1 then do;
      dcl hash h(dataset : "a",hashexp : 20);
      h.definekey("ID","DATE_ID");
      h.definedata("ID","Flag");
      h.definedone();
   end;

   set b;
   if 0 then set a;

   rc = h.find(key : ID, key : DATE_ID);
run;

 

Table W (What I am getting)

Date_IDIDCIDFlag
2019020214715222Y
2019020314715222Y
2019020414715222Y
2019020214715333Y
2019020314715333Y
2019020414715333Y
201902021295128444Y
201902031295128444Y
201902041295128444Y

 

Table W (what I am expecting)

Date_IDIDCIDFlag
2019020214715222Y
2019020314715222Y
2019020414715222Y
2019020214715333Y
2019020314715333Y
2019020414715333Y
201902021295128444 
201902031295128444 
201902041295128444 

 

Please help me correct error in my code. 

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

data w(drop=rc);
   if _N_ = 1 then do;
      dcl hash h(dataset : "a",hashexp : 20);
      h.definekey("ID","DATE_ID");
      h.definedata("ID","Flag");
      h.definedone();
   end;

   set b;
   if 0 then set a;
   call missing(flag);

   rc = h.find(key : ID, key : DATE_ID);
run;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Try this

 

data w(drop=rc);
   if _N_ = 1 then do;
      dcl hash h(dataset : "a",hashexp : 20);
      h.definekey("ID","DATE_ID");
      h.definedata("ID","Flag");
      h.definedone();
   end;

   set b;
   if 0 then set a;
   call missing(flag);

   rc = h.find(key : ID, key : DATE_ID);
run;
Myurathan
Quartz | Level 8
Thank you for your help. It works like a charm.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 1185 views
  • 2 likes
  • 3 in conversation