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:
ID | Address | Development |
1 | 208 PALADINO AVENUE | 0 |
2 | 4021 Broad Street | 1 |
3 | 121 111 Street | 1 |
4 | 123 456 Street | 1 |
5 | 161-141 River Road | 0 |
Development address list:
4021 Broad Street |
121 111 Street |
123 456 Street |
200-141 River Road |
500 PALADINO AVENUE |
Thank you.
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;
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.
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.