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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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