BookmarkSubscribeRSS Feed
ssas
Calcite | Level 5
Hi,

i have 2 tables
tableA with 360 records and 20 variables like fname lname postcode address1 add2 add3 dob age etc...

tableB with 165 records with 3 variables fname lname postcode.

if (tableb.lanme=tablea.lanme) and (tableb.postcode=tablea.postdoce)
then output tableA.

Output tableA should have only matching records with 20 variables
I am trying with merge in a, b, if a and b. but i am not getting the correct output.

Is there any simple sql or datastep to solve it.

Thanks in Advance,
Sams
2 REPLIES 2
daveryBBW
Calcite | Level 5
here's one way to do it ...

Steps 1 & 2 - sort your tables by the fields in common:
proc sort data=tableA; by fname lname postcode; run;
proc sort data=tableB; by fname lname postcode; run;

Step 3 - merge the data and output:
data tableC;
merge tableA (in=a) tableB (in=b);
by fname lname postcode;
if a and b then output;
run;

The (in=a) and (in=b) are just aliasing datasets. When you say IF A AND B THEN OUTPUT, you're basically telling it to do an inner join and output only the rows in common. As a note, if tableB had more than just the common fields, you could DROP the extra columns that you didn't want.

Hope this helps!
ssas
Calcite | Level 5
Thanks for you help
sams

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1151 views
  • 0 likes
  • 2 in conversation