example:
Var 1 as full_address '123 ABC STEET APT 305 MINNEAPOLIS MN 55332' and '333 5TH ST #3 SAINT PAUL 55343'
Var 2 as city 'EDINA' and 'SAINT PAUL'
if city exist in full_address, output the result
Below are few codes I tried didn't work.
Didn't work is awful vague.
Are there errors in the log?: Post the code and log in a code box opened with the "</>" to maintain formatting of error messages.
No output? Post any log in a code box.
Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results (at least for a sample). Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "</>" icon or attached as text to show exactly what you have and that we can test code against.
Warning: This forum seriously reformats text pasted into the main message windows. It will replace consecutive spaces with one (sometimes) other "white space" characters such as tabs as well. So any text you want to use for tests in string comparisons should be pasted into a text box. Really.
Code as well as sometimes strange non-printable characters appear that will prevent code from running correctly or at all.
Try adding STRIP(CITY) when using that as the search.
data work.MATCHING_CITY; set work.ADDR_DATA; if index(FULL_ADDRESS, strip(CITY) ) > 0 then do; output; end; run;
The behavior of INDEX, and most of the other string comparison functions, is that a variable will be padded with blanks to its defined length. Which means they are often way too long to find the target value in the source.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.