<?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: remove parentheses and add a leading zero in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319748#M70322</link>
    <description>&lt;P&gt;You may try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Phone_number = input(compress(area_code||number, &amp;nbsp;'()' ) , best.);&lt;/P&gt;
&lt;P&gt;format phone_number z12.; &amp;nbsp; /* adapt format length as need */&lt;/P&gt;</description>
    <pubDate>Sat, 17 Dec 2016 21:52:47 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2016-12-17T21:52:47Z</dc:date>
    <item>
      <title>remove parentheses and add a leading zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319715#M70299</link>
      <description>&lt;P&gt;please provide the below mentioned&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In a dataset there are two variables &amp;nbsp;,with one of the variable &amp;nbsp;has parentheses around them. Combine these into a single numeric variable called " and remove the parentheses and add a leading zero&lt;/P&gt;</description>
      <pubDate>Sat, 17 Dec 2016 10:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319715#M70299</guid>
      <dc:creator>nimu</dc:creator>
      <dc:date>2016-12-17T10:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: remove parentheses and add a leading zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319717#M70301</link>
      <description>&lt;P&gt;The question is misleading, as it is really not possible. &amp;nbsp;There is no such thing as a numeric variable that contains a leading zero. &amp;nbsp;If you know the length of a variable, you can print it with leading zeros but that's only the printing format. &amp;nbsp;The variable itself does not contain any leading zeros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TRANSLATE function handles this pretty easily but creates a character variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newvar&lt;FONT face="courier new,courier"&gt; = translate(&lt;/FONT&gt;oldvar&lt;FONT face="courier new,courier"&gt;, ' 0', ')(' )&lt;/FONT&gt;;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Dec 2016 11:23:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319717#M70301</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-17T11:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: remove parentheses and add a leading zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319725#M70308</link>
      <description>&lt;P&gt;A good idea is to post test data - in the form of a datastep - and what the output should look like. &amp;nbsp;This is so that we - who don't know what you have/are doing - can try to understand the problem and the required outcome. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your first variable will be character - numeric variables cannot have () in them. &amp;nbsp;Is the second variable numeric or character - you see this is where the test data in the form of a datastep comes in.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Numeric values do not have preceeding zeros, this can only be displayed using a format - Zx. shows numeric values , to length x, with zeroes padded at the front. &amp;nbsp;You can also put this result into a character if you want to retain the format outside the SAS system.&lt;/P&gt;
&lt;P&gt;So something like:&lt;/P&gt;
&lt;PRE&gt;data want;&lt;BR /&gt;  length result $50;
  set have;
  var1="(1234)";
  var2=5555;
  result=cats(put(tranwrd(var1,"()"),z6.),put(var2,best.));
run;&lt;/PRE&gt;
&lt;P&gt;Will put var1 without () into 6 characters padding the front with zeroes to make the length, then concatenating the var2 to this to form a final character result. &amp;nbsp;You could convert this reult to numeric and apply a Zx. format where x is the total length of var1+var2 if you like.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Dec 2016 13:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319725#M70308</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-17T13:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: remove parentheses and add a leading zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319728#M70311</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;The actual questions is&lt;BR /&gt;&lt;BR /&gt;1. You have a dataset called "Telephone_Number" which includes two&lt;BR /&gt;variables "Area_Code" and "Number". The "Area_Code" has parentheses around&lt;BR /&gt;them. Combine these into a single numeric variable called "Home_Number" and&lt;BR /&gt;remove the parentheses and add a leading zero.</description>
      <pubDate>Sat, 17 Dec 2016 14:15:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319728#M70311</guid>
      <dc:creator>nimu</dc:creator>
      <dc:date>2016-12-17T14:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: remove parentheses and add a leading zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319731#M70314</link>
      <description>&lt;P&gt;As you haven't confirmed what the data looks like, will still have to guess:&lt;/P&gt;
&lt;PRE&gt;data want;&lt;BR /&gt;  set have;
  var1="(1234)";
  var2=5555;
  result=input(cats(tranwrd(var1,"()"),put(var2,b&lt;WBR /&gt;est.)),best.);&lt;BR /&gt;  format result z9.;
run;&lt;/PRE&gt;
&lt;P&gt;This only &lt;STRONG&gt;displays&lt;/STRONG&gt; the data using Zx. format to show the extra 0, as said above numeric values do &lt;STRONG&gt;not&lt;/STRONG&gt; have the ability to hold preceeding zeroes.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Dec 2016 15:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319731#M70314</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-17T15:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: remove parentheses and add a leading zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319737#M70316</link>
      <description>&lt;P&gt;So you will need to do more of the work here. &amp;nbsp;There are too many pieces that could be defined one way or the other.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding the inputs: &amp;nbsp;Is NUMBER numeric or character? &amp;nbsp;Most phone numbers look more like 555-2134 with a dash in the middle that means it is character. &amp;nbsp;What is actually in your data? &amp;nbsp;If there is a dash there originally, do you want it removed?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding the output: &amp;nbsp;There still is no such thing as a numeric variable that contains a leading zero. &amp;nbsp;So what do you want? &amp;nbsp;A list of digits in a file, where the first digit is a zero? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Give a specific example showing what one line of input looks like, and what the corresponding output should be.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Dec 2016 17:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319737#M70316</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-17T17:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: remove parentheses and add a leading zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319748#M70322</link>
      <description>&lt;P&gt;You may try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Phone_number = input(compress(area_code||number, &amp;nbsp;'()' ) , best.);&lt;/P&gt;
&lt;P&gt;format phone_number z12.; &amp;nbsp; /* adapt format length as need */&lt;/P&gt;</description>
      <pubDate>Sat, 17 Dec 2016 21:52:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-parentheses-and-add-a-leading-zero/m-p/319748#M70322</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-17T21:52:47Z</dc:date>
    </item>
  </channel>
</rss>

