Find string, if does not exist, find another string

52 Views Asked by At

I have many files from OECD that have data available for different regional granularities. An example would be:

File A

REG_ID Region
AUS    Australia
AU1GS  Sydney
AU1    New South Wales
AU2    Victoria
AU2GM  Melbourne

File B

REG_ID Region
AUS    Australia
AU1GS  Sydney
AU2GM  Melbourne

File C

REG_ID Region
AUS    Australia
AU1    New South Wales
AU1GS  Sydney
AU2    Victoria

I want to extract the most granular region, in this case Sydney only, and not New South Wales. However, if Sydney is unavailable, I want to extract New South Wales.

How do I write code that is generalisable to all these files?

0

There are 0 best solutions below