<?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: Add country code to phone numbers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-country-code-to-phone-numbers/m-p/312209#M67681</link>
    <description>&lt;P&gt;Your rules are relatively clear, you can turn them into if/then statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use length to get the length of the phone number and Catt to add prefix.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes you have a character variable, but use PUT if you need to convert it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If length(phone) &amp;lt;= 7 then new_phone = catt('00632', phone);&lt;/P&gt;
&lt;P&gt;else if length(phone)=8 and substr(phone, 1, 1) = '2' then new_phone = catt('0063', phone);&lt;/P&gt;
&lt;P&gt;else ... etc&lt;/P&gt;</description>
    <pubDate>Thu, 17 Nov 2016 05:09:34 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-11-17T05:09:34Z</dc:date>
    <item>
      <title>Add country code to phone numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-country-code-to-phone-numbers/m-p/312185#M67668</link>
      <description>Hello! I Need to add country code(0063)to a list of phone numbers. My data looks like this:&lt;BR /&gt;Phone&lt;BR /&gt;4345121&lt;BR /&gt;464158245&lt;BR /&gt;29767111&lt;BR /&gt;998625676&lt;BR /&gt;63465126026&lt;BR /&gt;639208907675&lt;BR /&gt;&lt;BR /&gt;My problem is that the numbers are a mix of cellphone and landline with some numbers already have the country code(63).&lt;BR /&gt;The conditions are these:&lt;BR /&gt;1.If phone length &amp;lt;= 7 then newphone is 00632phone&lt;BR /&gt;2.If phone length=8 and frst digit =2 then newphone is 0063phone&lt;BR /&gt;3.If phone length=9 and first two digits are in(46,32,82 etc,) then newphone is 0063phone. &lt;BR /&gt;4.if phone length =11 and first two digits = 63 then newphone is 00phone&lt;BR /&gt;5. If phone length is 9 and first digit is 9 then newphone is 0063phone&lt;BR /&gt;6. If phone length is 12 and first 3 digits are 639 then newphone is 00phone. &lt;BR /&gt;&lt;BR /&gt;Newphone should look like this:&lt;BR /&gt;006324345121&lt;BR /&gt;0063464158245&lt;BR /&gt;006329767111&lt;BR /&gt;0063998625676&lt;BR /&gt;0063465126026&lt;BR /&gt;00639208907675&lt;BR /&gt;&lt;BR /&gt;Any help will be much appreciated.</description>
      <pubDate>Thu, 17 Nov 2016 02:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-country-code-to-phone-numbers/m-p/312185#M67668</guid>
      <dc:creator>JT99</dc:creator>
      <dc:date>2016-11-17T02:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: Add country code to phone numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-country-code-to-phone-numbers/m-p/312209#M67681</link>
      <description>&lt;P&gt;Your rules are relatively clear, you can turn them into if/then statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use length to get the length of the phone number and Catt to add prefix.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes you have a character variable, but use PUT if you need to convert it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If length(phone) &amp;lt;= 7 then new_phone = catt('00632', phone);&lt;/P&gt;
&lt;P&gt;else if length(phone)=8 and substr(phone, 1, 1) = '2' then new_phone = catt('0063', phone);&lt;/P&gt;
&lt;P&gt;else ... etc&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 05:09:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-country-code-to-phone-numbers/m-p/312209#M67681</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-17T05:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: Add country code to phone numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-country-code-to-phone-numbers/m-p/312221#M67685</link>
      <description>Thank you so much!</description>
      <pubDate>Thu, 17 Nov 2016 06:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-country-code-to-phone-numbers/m-p/312221#M67685</guid>
      <dc:creator>JT99</dc:creator>
      <dc:date>2016-11-17T06:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: Add country code to phone numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-country-code-to-phone-numbers/m-p/312234#M67692</link>
      <description>&lt;P&gt;like this &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data phonenumbers;
input phone $;
format phone $12.;
datalines;
4345121
464158245
29767111
998625676
63465126026
639208907675
;

data want(drop = code);
   set phonenumbers;
   if length(Phone) &amp;lt;= 7 then code = '00632';
   else if length(Phone) = 8 then code = '0063';
   else if length(Phone) = 9 and substr(Phone, 1, 2) in ('46', '32', '82') then code = '0063';
   else if length(Phone) = 11 and substr(Phone, 1, 2) = '63' then code = '00';
   else if length(Phone) = 9 and substr(Phone, 1, 1) = '9' then code = '0063';
   else if length(Phone) = 12 and substr(Phone, 1, 3) = '639' then code = '00';

   newphone = cats(code, phone);
   format newphone $12.;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Nov 2016 07:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-country-code-to-phone-numbers/m-p/312234#M67692</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-17T07:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Add country code to phone numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-country-code-to-phone-numbers/m-p/312260#M67703</link>
      <description>It worked! Thank you both so much!</description>
      <pubDate>Thu, 17 Nov 2016 10:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-country-code-to-phone-numbers/m-p/312260#M67703</guid>
      <dc:creator>JT99</dc:creator>
      <dc:date>2016-11-17T10:00:54Z</dc:date>
    </item>
  </channel>
</rss>

