Please help:
Using version 9.3 I have a dataset which is a list of NPO's around South Africa and is named NPOz. From the 26 variables one is named Address and as the name suggests it contains the physical addresses for all the observed NPO's. From the address variable, I want to extract the name of the city so as to keep those that are from Johannesburg and Pretoria and delete the rest. Please help me with the right code for this job.
@ZosTa wrote:
Please help:
Using version 9.3 I have a dataset which is a list of NPO's around South Africa and is named NPOz. From the 26 variables one is named Address and as the name suggests it contains the physical addresses for all the observed NPO's. From the address variable, I want to extract the name of the city so as to keep those that are from Johannesburg and Pretoria and delete the rest. Please help me with the right code for this job.
Please post example data.
Use a data step with datalines, so we can easily recreate your dataset.
With Excel, you have the problem that you need to rely on guessing procedures when importing.
Save the Excel data to a csv file, and post some sample lines (don't forget to anonymize if sensitive data is present) in a window opened with the {i} button, so we can see the file as-is. From that it will be possible to create a data step to read the csv.
You could maybe do it with index()
where index(upcase(address),"JOHANNESBURG") or index(upcase(address),"PRETORIA");
The index worked perfectly, Thank you RW9
Thank you everyone for your assistance, I used the index statement from RW9 and it works perfectly.
No worries. Just bear in mind that it is an exact match, miss-spellings for instance wouldn't get picked up. For that you would need a more complex algorithm, maybe using Regular Expressions, or some other pattern matching.
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.