<?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 Function to remove leading zeros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/61537#M13373</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I need to remove leading zeros from a SAS variable. I can only read that variable as character beacuse it contains both numbers &amp;amp; character values in it. Is there any function which will remove only the leading zeros from the variable?&lt;BR /&gt;
&lt;BR /&gt;
Thanks for ur help.&lt;BR /&gt;
Savi</description>
    <pubDate>Fri, 14 Nov 2008 07:30:01 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-11-14T07:30:01Z</dc:date>
    <item>
      <title>Function to remove leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/61537#M13373</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I need to remove leading zeros from a SAS variable. I can only read that variable as character beacuse it contains both numbers &amp;amp; character values in it. Is there any function which will remove only the leading zeros from the variable?&lt;BR /&gt;
&lt;BR /&gt;
Thanks for ur help.&lt;BR /&gt;
Savi</description>
      <pubDate>Fri, 14 Nov 2008 07:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/61537#M13373</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-11-14T07:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Function to remove leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/61538#M13374</link>
      <description>I'm not aware of any ready made function for this, but you could use the FINDC function with the V modifier to accomplish this:&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
	a='000dfsdf0';&lt;BR /&gt;
	b= substr(a,findc(a,'0','V'));&lt;BR /&gt;
	putlog _all_;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Fri, 14 Nov 2008 09:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/61538#M13374</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2008-11-14T09:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Function to remove leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/61539#M13375</link>
      <description>Try this small sample code&lt;BR /&gt;
[pre]&lt;BR /&gt;
data test;&lt;BR /&gt;
 string = '00123A0094';&lt;BR /&gt;
 name = prxchange('s/^(0*)/ /', -1, string);&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 14 Nov 2008 09:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/61539#M13375</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2008-11-14T09:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Function to remove leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/61540#M13376</link>
      <description>Hi Savi,&lt;BR /&gt;
If the only zeroes you have are leading zeroes you can do this:&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
x='000mgfse';&lt;BR /&gt;
y=compress(x,'0',' ');&lt;BR /&gt;
put _all_;&lt;BR /&gt;
run;</description>
      <pubDate>Sun, 16 Nov 2008 17:37:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/61540#M13376</guid>
      <dc:creator>yonib</dc:creator>
      <dc:date>2008-11-16T17:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: Function to remove leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/61541#M13377</link>
      <description>* If you want the character string left aligned, this should do it. ;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   lz = '000123';&lt;BR /&gt;
   dummy = input(lz,best12.);&lt;BR /&gt;
   lz    = put(dummy,best12. -L);&lt;BR /&gt;
   put lz= ;&lt;BR /&gt;
   drop dummy;&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 21 Nov 2008 20:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/61541#M13377</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-11-21T20:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: Function to remove leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/61542#M13378</link>
      <description>try[pre]   if old_var =:'0' &lt;BR /&gt;
      then new_var = substr( old_var, verify( old_var,'0' ) );&lt;BR /&gt;
      else new_var = old_var ;[/pre]&lt;BR /&gt;
Of course, there may be a more concise way.&lt;BR /&gt;
Here is a SASlog to demonstrate[pre]49   data ;&lt;BR /&gt;
50      input old_var $ ;&lt;BR /&gt;
51      if old_var =:'0'&lt;BR /&gt;
52         then new_var = substr( old_var, verify( old_var,'0' ) );&lt;BR /&gt;
53         else new_var = old_var ;&lt;BR /&gt;
54      put old_var= / new_var= /;&lt;BR /&gt;
55   cards;&lt;BR /&gt;
 &lt;BR /&gt;
old_var=0`120345&lt;BR /&gt;
new_var=`120345&lt;BR /&gt;
 &lt;BR /&gt;
old_var=asdf3450&lt;BR /&gt;
new_var=asdf3450&lt;BR /&gt;
 &lt;BR /&gt;
old_var=00090807&lt;BR /&gt;
new_var=90807&lt;BR /&gt;
 &lt;BR /&gt;
old_var=0zxcvbnm&lt;BR /&gt;
new_var=zxcvbnm&lt;BR /&gt;
NOTE: The&lt;BR /&gt;
[/pre]&lt;BR /&gt;
It can be achieved in a single statement with the new SAS9.2 function IFC()...[pre]76   data ;&lt;BR /&gt;
77      input old_var $ ;&lt;BR /&gt;
78      new_var= ifc( old_var =:'0'&lt;BR /&gt;
79                    , substr( old_var, verify( old_var,'0' ) )&lt;BR /&gt;
80                    , old_var );&lt;BR /&gt;
81      put old_var= / new_var= /;&lt;BR /&gt;
82   cards;&lt;BR /&gt;
 &lt;BR /&gt;
old_var=0`120345&lt;BR /&gt;
new_var=`120345&lt;BR /&gt;
 &lt;BR /&gt;
old_var=asdf3450&lt;BR /&gt;
new_var=asdf3450&lt;BR /&gt;
 &lt;BR /&gt;
old_var=00090807&lt;BR /&gt;
new_var=90807&lt;BR /&gt;
 &lt;BR /&gt;
old_var=0zxcvbnm&lt;BR /&gt;
new_var=zxcvbnm&lt;BR /&gt;
NOTE: The&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
It helps that the (very) old function VERIFY() returns the position in a string where a character occurs that is not in the list of characters to "verify".&lt;BR /&gt;
&lt;BR /&gt;
PeterC</description>
      <pubDate>Fri, 21 Nov 2008 21:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/61542#M13378</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2008-11-21T21:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: Function to remove leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/230532#M41817</link>
      <description>WOW! awesome function, thnx!</description>
      <pubDate>Mon, 19 Oct 2015 06:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/230532#M41817</guid>
      <dc:creator>GenDemo</dc:creator>
      <dc:date>2015-10-19T06:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: Function to remove leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/230535#M41819</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13642"&gt;@GertNissen﻿&lt;/a&gt;'s RegEx needs a small amendment: Remove the blank between the "/ /" as else you're replacing leading zero's with a blank instead of only removing the zeroes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  string = '00123A0094';
  name = prxchange('s/^(0*)//', -1, string);
run&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Oct 2015 08:29:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-remove-leading-zeros/m-p/230535#M41819</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-19T08:29:07Z</dc:date>
    </item>
  </channel>
</rss>

