<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Extract Country Names / Codes from a free text column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-Country-Names-Codes-from-a-free-text-column/m-p/514776#M138836</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input text $50.;
cards;
Further Credit to Bank ABC IRAN
Forward Credit to India from Salman Ali
For further credit from Bank XYZ USA to Account of Rakesh Roy
Forward Credit to Bank in United States of America from Salman Ali
run;

data countries;
input country $30.;
cards;
USA
India
United States of America
Iran
;
run;

data want;
set have;

found=0;
do i=1 to nrows;
    set countries point=i nobs=nrows;
        if find(text, country, 'it') then do;
	    found=1;
            leave;
        end;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 20 Nov 2018 15:15:26 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2018-11-20T15:15:26Z</dc:date>
    <item>
      <title>Extract Country Names / Codes from a free text column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Country-Names-Codes-from-a-free-text-column/m-p/514772#M138834</link>
      <description>&lt;P&gt;Is there any way to extract Country Name/ Codes from a free text column containing country name/code? There is no pattern in the free text i.e. the name/code of country can be at any place, start, end or middle in the free text.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below are the sample values from free text column:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Further Credit to Bank ABC IRAN&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Forward Credit to India from Salman Ali&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;For further credit from Bank XYZ USA to Account of Rakesh Roy&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Forward Credit to Bank in United States of America from Salman Ali&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From above free texts, I have to find out all country names / codes available and store it in a new field. Can you please suggest any way possible to do this? I have a table with all country names &amp;amp; their codes.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 14:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Country-Names-Codes-from-a-free-text-column/m-p/514772#M138834</guid>
      <dc:creator>manishiiita</dc:creator>
      <dc:date>2018-11-20T14:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Country Names / Codes from a free text column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Country-Names-Codes-from-a-free-text-column/m-p/514776#M138836</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input text $50.;
cards;
Further Credit to Bank ABC IRAN
Forward Credit to India from Salman Ali
For further credit from Bank XYZ USA to Account of Rakesh Roy
Forward Credit to Bank in United States of America from Salman Ali
run;

data countries;
input country $30.;
cards;
USA
India
United States of America
Iran
;
run;

data want;
set have;

found=0;
do i=1 to nrows;
    set countries point=i nobs=nrows;
        if find(text, country, 'it') then do;
	    found=1;
            leave;
        end;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Nov 2018 15:15:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Country-Names-Codes-from-a-free-text-column/m-p/514776#M138836</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-11-20T15:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Country Names / Codes from a free text column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Country-Names-Codes-from-a-free-text-column/m-p/514777#M138837</link>
      <description>&lt;P&gt;If you have the list then you can use that.&amp;nbsp; For instance - and I have no test data for either dataset (in the form of a datastep!) to use so this is just sample code:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set countries end=last;
  if _n_=1 then call execute('data want; set have;');
  call execute('if index(free_text,"',strip(country),'" then country="',strip(country),'";');
  if last then call execute('run;');
run;&lt;/PRE&gt;
&lt;P&gt;What this will do is generate a datastep with an if statement for each country in your list of countries.&amp;nbsp; This new datastep then gets run.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 15:19:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Country-Names-Codes-from-a-free-text-column/m-p/514777#M138837</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-20T15:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Country Names / Codes from a free text column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Country-Names-Codes-from-a-free-text-column/m-p/514780#M138839</link>
      <description>If you have MapsGFK library then you can get a list of the countries using:&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table countries as&lt;BR /&gt;select distinct idname&lt;BR /&gt;from mapsgfk.world;&lt;BR /&gt;quit;</description>
      <pubDate>Tue, 20 Nov 2018 15:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Country-Names-Codes-from-a-free-text-column/m-p/514780#M138839</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-20T15:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Country Names / Codes from a free text column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Country-Names-Codes-from-a-free-text-column/m-p/514786#M138841</link>
      <description>&lt;P&gt;another way I can think of by using lookup table and prxchange.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*have a lookuptable with all your values*/
data lookup;
value ="IRAN|INDIA|USA|United States of America";
run;


/*this is your table*/
data mytable;
length col1 $200.;
col1= "Further Credit to Bank ABC IRAN";
output;
col1= "Forward Credit to India from Salman Ali";
output;
col1= "For further credit from Bank XYZ USA to Account of Rakesh Roy";
output;
col1= "Forward Credit to Bank in United States of America from Salman Al"
;
output;
run;

/*create  macrovariable to use this  in your prxchange query */
data _null_;
set lookup;
call symputx("value", value);
run;
%put &amp;amp;value;

data final;
set mytable;
suffix = prxchange("s/(.*)(&amp;amp;value)(.*)/$2/i", -1, col1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Nov 2018 15:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Country-Names-Codes-from-a-free-text-column/m-p/514786#M138841</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-11-20T15:45:11Z</dc:date>
    </item>
  </channel>
</rss>

