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-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!

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