Hello,
I have a string variable named affil1, which is the full affiliation of an author appearing on a paper:
the contents in this variable always take the following structure:
Department, University Name, ZIP Code, Region, Country
I would like to extract the portion containing the "country" and create a new variable (Country) with this information.
So, basically I need to extract the portion after the last comma (or the portion after the first comma, if we count from the right).
I've made some attempts by combining substr and strpos, but results are not satisfactory so far.
Also, note that some countries contain more than one word (e.g. united states).
Any help would be highly appreciated.
Thanks a lot.
I have a string variable named affil1, which is the full affiliation of an author appearing on a paper:
Code:
storage display value variable name type format label variable label ---------------------------------------------------------------------------------------------------------- affil1 str255 %255s
Department, University Name, ZIP Code, Region, Country
I would like to extract the portion containing the "country" and create a new variable (Country) with this information.
So, basically I need to extract the portion after the last comma (or the portion after the first comma, if we count from the right).
I've made some attempts by combining substr and strpos, but results are not satisfactory so far.
Code:
gen country = substr(affil1, strpos(affil1, ","), .)
Any help would be highly appreciated.
Thanks a lot.
Comment