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

Hi in table table1 and table2 i want to create table l3 from table1 and table2 tables based on table2.id2 =table.id
i want to do it on hash keys

data table1;
input id id2;
cards;
1 2
2 3
3 4
4 5
run;

data table2;
input id id2;
cards;
2 3
run;

output
id id2
3 4

1 ACCEPTED SOLUTION

Accepted Solutions
sas_Forum
Calcite | Level 5

Thqs Ksharp i know you will Reply

View solution in original post

3 REPLIES 3
sas_Forum
Calcite | Level 5

I can do same in joins

proc sql;
create table l3 as select a.id,a.id2 from table1 as a right join table2 as b
on a.id=b.id2;
quit;
proc print;run;

Ksharp
Super User

OK. Easy.

Assuming your id2 in table2 has no replicated value.

data table1;
input id id2;
cards;
1 2
2 3
3 4
4 5
;
run;

data table2;
input id id2;
cards;
2 3
;
run;

data want;
 if _n_ eq 1 then do;
  if 0 then set table2;
  declare hash ha(dataset:'table2', hashexp:10);
   ha.definekey('id2');
   ha.definedone();
 end;
 set table1;
  if ha.check(key:id)=0 then output;
run;



Ksharp

sas_Forum
Calcite | Level 5

Thqs Ksharp i know you will Reply

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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