Help using Base SAS procedures

Merge two datasets

Reply
Contributor
Posts: 23

Merge two datasets

Hi all,

Thanks for taking time to help me.

I have two datasets which I want to merge on people's surname.

In one dataset the field contains just the surname but in the other dataset the field contains other words (potentially before or after the surname).

Is there any way to join the two datasets?

E.g. Surname (table 1)        Name (table 2)


          Smith                        Mr.Tom Smith     


I would want to join the records for this example above.


I have tried using proc sql, create table ... with a where clause with the contains function but that did not work.

I have SAS 9.4.

Any help will be much appreciated.

Trusted Advisor
Posts: 1,228

Re: Merge two datasets

proc sql;

select * from table1,table2

where table2.name contains strip(table1.surname);

quit;

Valued Guide
Posts: 2,177

Re: Merge two datasets

stat@sas wrote:

proc sql;

select * from table1,table2

where upcase( table2.surname ) contains upcase( strip(table1.surname) ) ;

quit;

with a little update in case SurName is not reliably in a consistent case

good luck

Contributor
Posts: 23

Re: Merge two datasets

Thank you both for your help, that is great. Smiley Happy

Ask a Question
Discussion stats
  • 3 replies
  • 213 views
  • 6 likes
  • 3 in conversation