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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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