<?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: Format phone numbers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Format-phone-numbers/m-p/706248#M216754</link>
    <description>&lt;P&gt;Do you have any international numbers? These may show up as 2 digits in front of other digits and not in a typical 3 digit area code , 3 digit exchange and 4 digit block.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Learned this the hard way with code similar to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt; used on some international numbers in the middle of data that was mostly US that moved them from Central America to Colorado because the local phone number was 2 digits shorter than than the US and the international code provided just enough to replace them and make something that looked like a US phone number.&lt;/P&gt;</description>
    <pubDate>Wed, 16 Dec 2020 08:54:37 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-12-16T08:54:37Z</dc:date>
    <item>
      <title>Format phone numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-phone-numbers/m-p/706198#M216725</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have data sets that have mixed formats of phone numbers such as:&lt;/P&gt;&lt;P&gt;+1 (915) 111-1111&lt;/P&gt;&lt;P&gt;+ (202) 509-3114&lt;/P&gt;&lt;P&gt;+1 (915) 1234567&lt;/P&gt;&lt;P&gt;+ (202) 5093114&lt;/P&gt;&lt;P&gt;(777) 123-4567&lt;/P&gt;&lt;P&gt;3334445678&lt;/P&gt;&lt;P&gt;123.222.1334&lt;/P&gt;&lt;P&gt;How can I standardize the numbers into the following format:&lt;/P&gt;&lt;P&gt;717-333-4545&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 03:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-phone-numbers/m-p/706198#M216725</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2020-12-16T03:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Format phone numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-phone-numbers/m-p/706213#M216732</link>
      <description>Hey, check with this&lt;BR /&gt;&lt;BR /&gt;data test;&lt;BR /&gt;	col1 = "+1 (915) 111-1111";&lt;BR /&gt;	output;&lt;BR /&gt;	col1 = "+ (202) 509-3114";&lt;BR /&gt;	output;&lt;BR /&gt;	col1 = "+1 (915) 1234567";&lt;BR /&gt;	output;&lt;BR /&gt;	col1 = "+ (202) 5093114";&lt;BR /&gt;	output;&lt;BR /&gt;	col1 = "(777) 123-4567";&lt;BR /&gt;	output;&lt;BR /&gt;	col1 = "3334445678";&lt;BR /&gt;	output;&lt;BR /&gt;	col1 = "123.222.1334";&lt;BR /&gt;	output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;	set test;&lt;BR /&gt;	col2 = tranwrd (col1,"+1","");&lt;BR /&gt;	col3 = compress(col2, '(+.  -)', 'a');&lt;BR /&gt;	col4 = catx("-",substr(col3,1,3), substr(col3,4,3), substr(col3,7,4));&lt;BR /&gt;run;</description>
      <pubDate>Wed, 16 Dec 2020 05:14:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-phone-numbers/m-p/706213#M216732</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2020-12-16T05:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Format phone numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-phone-numbers/m-p/706219#M216737</link>
      <description>&lt;P&gt;Another task for one of my favourite functions: prxchange:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input phoneNumber $20.;
   datalines;
+1 (915) 111-1111
+ (202) 509-3114
+1 (915) 1234567
+ (202) 5093114
(777) 123-4567
3334445678
123.222.1334
;

data want;
   set have;
   
   phoneNumber = prxchange('s/.*(\d{3})\D*(\d{3})\D*(\d{4})/$1-$2-$3/', -1, phoneNumber);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;.* matches anything&lt;/P&gt;
&lt;P&gt;(\d{3}) = three digits, the brackets create a capture-group&lt;/P&gt;
&lt;P&gt;\D* = zero or more non-digits&lt;/P&gt;
&lt;P&gt;$1 = the first capture-group&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 05:56:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-phone-numbers/m-p/706219#M216737</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-12-16T05:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: Format phone numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-phone-numbers/m-p/706248#M216754</link>
      <description>&lt;P&gt;Do you have any international numbers? These may show up as 2 digits in front of other digits and not in a typical 3 digit area code , 3 digit exchange and 4 digit block.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Learned this the hard way with code similar to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt; used on some international numbers in the middle of data that was mostly US that moved them from Central America to Colorado because the local phone number was 2 digits shorter than than the US and the international code provided just enough to replace them and make something that looked like a US phone number.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 08:54:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-phone-numbers/m-p/706248#M216754</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-16T08:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: Format phone numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-phone-numbers/m-p/706255#M216758</link>
      <description>&lt;P&gt;Make sure you deal correctly with&lt;/P&gt;
&lt;PRE&gt;+43699555123445&lt;/PRE&gt;
&lt;P&gt;Simply discarding the global country code will get you in trouble.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 09:10:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-phone-numbers/m-p/706255#M216758</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-16T09:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: Format phone numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-phone-numbers/m-p/706483#M216825</link>
      <description>&lt;P&gt;This actually worked thank you so much&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 23:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-phone-numbers/m-p/706483#M216825</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2020-12-16T23:25:27Z</dc:date>
    </item>
  </channel>
</rss>

