Help using Base SAS procedures

output selective records

Reply
Contributor
Posts: 43

output selective records

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
Occasional Contributor
Posts: 8

Re: output selective records

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!
Contributor
Posts: 43

Re: output selective records

Posted in reply to daveryBBW
Thanks for you help
sams
Ask a Question
Discussion stats
  • 2 replies
  • 149 views
  • 0 likes
  • 2 in conversation