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

Hello Experts,

I would like to run the Inner join.

My data is : TEST_1, TEST_2 ........TEST_100

 

I don't know how to indicate the inner join with : if in=IN1 and in=IN2 and and in=IN3 .....and in=IN100 )

I'm starting my code as :

	data result;
	  merge TEST_1 (in=in1) - TEST_100 (in=in100);
	  by  ID;
	  if in=in1 and in=in100  /* ?*/
    run;

Thank you for your help !

 

 

1 ACCEPTED SOLUTION
7 REPLIES 7
himofhimself
Fluorite | Level 6
data result;
	  merge TEST_1 (in=in1) - TEST_100 (in=in100);
	  by  ID;
	  if in1 and in100; /* ?*/
    run;

Another way using proc sql 

PROC SQL;
Create table result as
Select * from test_1 as in1, test_100 as in100
where in.ID = in100.ID;
Quit;

Both codes will  returns rows common to both tables (data sets). 

SASdevAnneMarie
Barite | Level 11
Thank you,
But I need to do the inner join for all my tables: test_1, test_2, test_3,....test_99, test_100.
himofhimself
Fluorite | Level 6
data result;
merge TEST_1 (in=in1) - TEST_100 (in=in100);
by ID;
If sum(of in1-in100) =100;
run;
Hope this works
SASdevAnneMarie
Barite | Level 11
Thank you !
It doesn't work, seems that I can't write (in=in1) and (in=in100) after the tables names in condition TEST_1 (in=in1) - TEST_100 (in=in100)
himself
Pyrite | Level 9

Have tried to come up with a macro, kindly give it a try🤔

%macro mergeHelper;
     %local i;
     %do I=1 %to 100;
          Test_&i(in=in&i)
      %end;
%mend mergeHelper;

Data merged;
   Merge
      %mergeHelper;
      If sum(of in1-in100)=100;
Run;
SASdevAnneMarie
Barite | Level 11
Thank you Kurt !

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 7 replies
  • 2338 views
  • 1 like
  • 4 in conversation