<?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: How to convert to a Standard Phone Number? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823853#M325338</link>
    <description>&lt;P&gt;The A at the head of the column says the values are character, which is likely best for phone numbers as you shouldn't do arithmetic with them, not numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since I am familiar with about a dozen "standard" formats for telephone numbers you need to show what you expect for a result. If it involves adding spaces, hyphens, parentheses, dots or other character then likely you need to create a new variable to hold the additional characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data example;
   phone='9046557747';
   newphone=cat('(',substr(phone,1,3),') ',substr(phone,4,3),'-',substr(phone,7,4));
run;&lt;/PRE&gt;
&lt;P&gt;Likely whatever you use will involve the 3 calls to the substr function if you want area code, exchange and number.&lt;/P&gt;
&lt;P&gt;However, if any of you numbers involving international numbers with a national code you will need to determine that and apply different rules.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Jul 2022 14:36:42 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-07-18T14:36:42Z</dc:date>
    <item>
      <title>How to convert to a Standard Phone Number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823847#M325336</link>
      <description>&lt;P&gt;I have the following list of numeric phone numbers and I want to convert them to standard phone number. Can someone recommend the best code for this? I cannot figure out where to even start with this.&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LMSSAS_0-1658153935766.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73403i26194A57D0E78FCA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LMSSAS_0-1658153935766.png" alt="LMSSAS_0-1658153935766.png" /&gt;&lt;/span&gt;&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>Mon, 18 Jul 2022 14:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823847#M325336</guid>
      <dc:creator>LMSSAS</dc:creator>
      <dc:date>2022-07-18T14:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to a Standard Phone Number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823853#M325338</link>
      <description>&lt;P&gt;The A at the head of the column says the values are character, which is likely best for phone numbers as you shouldn't do arithmetic with them, not numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since I am familiar with about a dozen "standard" formats for telephone numbers you need to show what you expect for a result. If it involves adding spaces, hyphens, parentheses, dots or other character then likely you need to create a new variable to hold the additional characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data example;
   phone='9046557747';
   newphone=cat('(',substr(phone,1,3),') ',substr(phone,4,3),'-',substr(phone,7,4));
run;&lt;/PRE&gt;
&lt;P&gt;Likely whatever you use will involve the 3 calls to the substr function if you want area code, exchange and number.&lt;/P&gt;
&lt;P&gt;However, if any of you numbers involving international numbers with a national code you will need to determine that and apply different rules.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 14:36:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823853#M325338</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-18T14:36:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to a Standard Phone Number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823854#M325339</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;I missed that these are characters, thanks for pointing that out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not have any international all US numbers. The format I'm looking for (904) 655-7747. it looks like the code you provided will give me that format.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One more question, I have an entire list of phone numbers, how do I get SAS to consume the entire column and not just a specific phone number? this is an elementary question, I know. Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 14:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823854#M325339</guid>
      <dc:creator>LMSSAS</dc:creator>
      <dc:date>2022-07-18T14:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to a Standard Phone Number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823859#M325342</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393528"&gt;@LMSSAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;I missed that these are characters, thanks for pointing that out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not have any international all US numbers. The format I'm looking for (904) 655-7747. it looks like the code you provided will give me that format.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One more question, I have an entire list of phone numbers, how do I get SAS to consume the entire column and not just a specific phone number? this is an elementary question, I know. Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I am not sure what you mean by "consume the entire column".&lt;/P&gt;
&lt;P&gt;If this has anything to do with reading in an external file then you should provide an example of the file and the desired results.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 15:03:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823859#M325342</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-18T15:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to a Standard Phone Number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823869#M325347</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393528"&gt;@LMSSAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;One more question, I have an entire list of phone numbers, how do I get SAS to consume the entire column and not just a specific phone number? this is an elementary question, I know. Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You would have to work very hard to have it NOT do the same thing for every observation.&lt;/P&gt;
&lt;P&gt;That is how a basic data step works.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
....
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Jul 2022 15:18:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823869#M325347</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-18T15:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to a Standard Phone Number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823875#M325348</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;I have an entire column in my sas sata set of diffrent&amp;nbsp; phone numbers. if i use the code below i get blanks or Nulls, since I can not enter each phone number individually, I was asking if there is a way to transform every phone number in my sas data set to a standard phone number.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LMSSAS_1-1658157673804.png" style="width: 383px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73409iB40C6A35EB9D3D0B/image-dimensions/383x72?v=v2" width="383" height="72" role="button" title="LMSSAS_1-1658157673804.png" alt="LMSSAS_1-1658157673804.png" /&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 example;
phone=AGENT_WORK_PHONE_NUMBER;
newphone=cat('(',substr(phone,1,3),') ',substr(phone,4,3),'-',substr(phone,7,4));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LMSSAS_0-1658157609387.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73408iB3D56E9BE95AA8D7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LMSSAS_0-1658157609387.png" alt="LMSSAS_0-1658157609387.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 15:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823875#M325348</guid>
      <dc:creator>LMSSAS</dc:creator>
      <dc:date>2022-07-18T15:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to a Standard Phone Number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823878#M325349</link>
      <description>&lt;BR /&gt;Thanks, Tom &lt;BR /&gt;Yes, i guess that was my last question. Is it a Dats Step that would create this? &lt;BR /&gt;It sounds like all the (original) phone characters would have to be identical for this to wrk.</description>
      <pubDate>Mon, 18 Jul 2022 15:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823878#M325349</guid>
      <dc:creator>LMSSAS</dc:creator>
      <dc:date>2022-07-18T15:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to a Standard Phone Number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823882#M325350</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393528"&gt;@LMSSAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;Thanks, Tom &lt;BR /&gt;Yes, i guess that was my last question. Is it a Dats Step that would create this? &lt;BR /&gt;It sounds like all the (original) phone characters would have to be identical for this to wrk.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The PHONE variable I created as an example. That is not your variable.&lt;/P&gt;
&lt;P&gt;Replace "Phone" with the name of your variable that I thought was just too long to type for an example since you only provided a PICTURE of data. Do not use the "phone= ...;" line as that was just to provide one value as an example of how the code might work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 16:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823882#M325350</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-18T16:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to a Standard Phone Number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823883#M325351</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393528"&gt;@LMSSAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;Thanks, Tom &lt;BR /&gt;Yes, i guess that was my last question. Is it a Dats Step that would create this? &lt;BR /&gt;It sounds like all the (original) phone characters would have to be identical for this to wrk.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I think you are just confusing yourself.&amp;nbsp; Since you did not post any example data (just a photograph) someone replied with an example using a single example phone number to show how it could work.&amp;nbsp; Don't use the the example phone number.&amp;nbsp; Just use the variable you already have with the phone numbers in it.&amp;nbsp; The key thing you need to take is the code that converts the strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So IF your actual dataset is named HAVE a looks something like this data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input phone $10.;
cards;
9046557747
2015551234
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then the data step you want to run to create the new dataset named WANT will look something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length pretty_phone $13;
  pretty_phone=cats('(',substr(phone,1,3),')',substr(phone,4,3),'-',substr(phone,7));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So each iteration of the data step will take the current value of the variable (a.k.a. "column") PHONE and generate the new variable PRETTY_PHONE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs      phone       pretty_phone

 1     9046557747    (904)655-7747
 2     2015551234    (201)555-1234
&lt;/PRE&gt;
&lt;P&gt;To run it for your data just change the input and output dataset names and the input and output variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 16:12:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823883#M325351</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-18T16:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to a Standard Phone Number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823891#M325352</link>
      <description>&lt;P&gt;I'd suggest use the tools SAS provides, a picture format in this case.&amp;nbsp; You can modify the proc format picture statement to test for incorrrect telephone numbers.&lt;BR /&gt;Edit:&amp;nbsp; Just noticed your input data is aphanumeric, so I modified my original code&lt;/P&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  picture telno (default=16)
    low - high= '999) 999-9999' (prefix='(');
 run;
 
 data have;
 length agt_wrk_num $16;
 input agt_wrk_num $;
 agt_wrk_conv=put(input(agt_wrk_num,best.),telno.);
 datalines;
 9046557747
 9547538080
 2399616606
 ;
  
 proc print;
 run;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ghosh_0-1658162018011.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73417iB01FCA44263AC4F3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ghosh_0-1658162018011.png" alt="ghosh_0-1658162018011.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 17:07:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823891#M325352</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2022-07-18T17:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to a Standard Phone Number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823914#M325362</link>
      <description>&lt;P&gt;You would need to convert variable phone to numeric type first: &lt;BR /&gt;phone_num = input(phone, 8.);&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 17:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/823914#M325362</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-07-18T17:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to a Standard Phone Number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/824217#M325470</link>
      <description>Thank you!&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Jul 2022 18:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/824217#M325470</guid>
      <dc:creator>LMSSAS</dc:creator>
      <dc:date>2022-07-19T18:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to a Standard Phone Number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/824218#M325471</link>
      <description>Thank you!</description>
      <pubDate>Tue, 19 Jul 2022 18:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-to-a-Standard-Phone-Number/m-p/824218#M325471</guid>
      <dc:creator>LMSSAS</dc:creator>
      <dc:date>2022-07-19T18:49:29Z</dc:date>
    </item>
  </channel>
</rss>

