DATA Step, Macro, Functions and more

Matching addresses to a list and creating a new variable

Reply
Contributor
Posts: 55

Matching addresses to a list and creating a new variable

Hi everyone,

 

My main dataset that contains a list of people and their home address. I have another data set that contains addresses that belong to a specific development. I'd like to create create a new variable in the main dataset that indiciates if the addresses belongs to a development. It could be a simple yes / no. Any direction would be greatly appreciated. Here is some sample data:

 

Main Dataset:

 

IDAddressDevelopment
1208 PALADINO AVENUE0
24021 Broad Street1
3121 111 Street1
4123 456 Street1
5161-141 River Road0

 

 

Development address list:

4021 Broad Street
121 111 Street
123 456 Street
200-141 River Road
500 PALADINO AVENUE

 

Thank you.

Frequent Contributor
Posts: 75

Re: Matching addresses to a list and creating a new variable

Try this:

data main;
infile datalines truncover;
input ID address $ 3-25;
datalines;
1 208 PALADINO AVENUE
2 4021 Broad Street
3 121 111 Street
4 123 456 Street
5 161-141 River Road
;
run;

data development;
set main(where=(id in (2,3,4)));
drop id;
run;

proc sort data=main;
by address;
run;

proc sort data=development;
by address;
run;

*if record is present in both datasets, set Development to 1; 
data mainout;
merge main(in=a) development(in=b);
by address;
Development=(a and b);
run;

Super User
Posts: 11,343

Re: Matching addresses to a list and creating a new variable

Depending on the quality of your data you may need to do some things to get good matches. For instance you may have data in either of the data sets that is inconsistent about abbreviations for common address terms: Street may appear as St or St. Capitalization is another issue. You show one address with ALL CAPITOL LETTERS but not the others. If one data set has "208 PALADINO AVENUE" and the other "208 Paladino Avenue" then they may not match.

You may also need to insure there is only one space between each item.

Ask a Question
Discussion stats
  • 2 replies
  • 115 views
  • 0 likes
  • 3 in conversation