<?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: Drop leading zeros from character variable in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444403#M28729</link>
    <description>&lt;P&gt;You can use the VERIFY() function to find the location of the first non-zero character.&amp;nbsp; You can then use that information in the SUBSTR() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input str $20. ;
  new_str = substr(str,verify(str,'0'));
  put (_all_) (= $quote.);
cards;
123
00ABC
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 10 Mar 2018 15:39:51 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-03-10T15:39:51Z</dc:date>
    <item>
      <title>Drop leading zeros from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444199#M28713</link>
      <description>&lt;P&gt;I have an employee number field that can be anywhere from 5 to 8 alpha-characters.&amp;nbsp; The field is 10 characters wide and the employee number is prefaced with leading zeros to fill the field.&amp;nbsp; There may or may not be zeros in the actual employee number.&amp;nbsp; I use only the EG interface to build queries and design summary reports.&amp;nbsp; How can I add a computed field to trim the employee number of any leading zeros?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, in advance for your assistance!&lt;/P&gt;&lt;P&gt;Rita Yee&lt;/P&gt;&lt;P&gt;Project Engineer&lt;/P&gt;&lt;P&gt;FedEx Express&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 18:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444199#M28713</guid>
      <dc:creator>RPYee</dc:creator>
      <dc:date>2018-03-09T18:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: Drop leading zeros from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444206#M28714</link>
      <description>&lt;P&gt;Are the employee numbers actually numbers, or can they contain any non-digit characters?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 18:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444206#M28714</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-09T18:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: Drop leading zeros from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444209#M28715</link>
      <description>&lt;P&gt;If you know that&amp;nbsp;zeroes never occur except as left-hand leading characters, then the translate function works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  x=translate(x,' ','0');
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note the 2nd and 3rd arguments of translate may not be in the intutitively expected order.&amp;nbsp; TRANSLATE converts the 3rd character (0) to the 2nd character (' ').&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Added note.&amp;nbsp; If you can have non-leading zeroes that you want to preserve:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  do while (x=:'0');
    x=substr(x,2);
  end;
  x=right(x);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Mar 2018 01:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444209#M28715</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-03-10T01:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Drop leading zeros from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444292#M28717</link>
      <description>&lt;P&gt;If your source variable (let's call it emp_id) is numeric then just change the format on it - i.e. assign format BEST32.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If emp_id is character and you're sure it only contains digits then use an informat to convert the string to a number:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;emp_id_want=input(emp_id,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;best32.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If emp_id can contain alphanumeric characters then code like below should do the trick:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;emp_id_want=prxchange(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'s/^\s*0*//oi'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,emp_id);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 22:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444292#M28717</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-03-09T22:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Drop leading zeros from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444400#M28728</link>
      <description>&lt;P&gt;Hi, Rita&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Glad to see you're persevering with SAS!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To put the advice in the above posts into an EG context, create a new computed column, and make it an advanced expression.&lt;/P&gt;
&lt;P&gt;You can use all of the functions described above in the advanced expression. Here's another way, assuming that your fields can only contain digits. I'm using EmpID as the field name; just change as needed, and drop this into the "Enter an expression" box:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;right(put(input(EmpID, best10.),best10.))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's first using the input function to convert your character field to a number, then using the put function to convert the number back to character (the best10. format will put in leading blanks.) Then the right function shifts the non-blank characters to the right of the field.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Sat, 10 Mar 2018 15:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444400#M28728</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2018-03-10T15:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Drop leading zeros from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444403#M28729</link>
      <description>&lt;P&gt;You can use the VERIFY() function to find the location of the first non-zero character.&amp;nbsp; You can then use that information in the SUBSTR() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input str $20. ;
  new_str = substr(str,verify(str,'0'));
  put (_all_) (= $quote.);
cards;
123
00ABC
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Mar 2018 15:39:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444403#M28729</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-10T15:39:51Z</dc:date>
    </item>
    <item>
      <title>Re: Drop leading zeros from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444909#M28770</link>
      <description>They are only numbers.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 12 Mar 2018 19:44:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444909#M28770</guid>
      <dc:creator>RPYee</dc:creator>
      <dc:date>2018-03-12T19:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Drop leading zeros from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444973#M28781</link>
      <description>&lt;P&gt;Then do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;empnum = strip(put(input(empnum,best.),best.));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Mar 2018 23:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/444973#M28781</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-12T23:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: Drop leading zeros from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/445007#M28782</link>
      <description>Better to use 32. as the INFORMAT and 32. as the FORMAT.&lt;BR /&gt;The BEST format will default to 12 characters and larger integers will be presented in scientific format.  Since the values are by definition integers then just tell SAS that. 32 is the maximum width.&lt;BR /&gt;Also for informats there is no real BEST informat.  If you use BEST as an informat is just an **alias** for the normal NN. informat.  Calling it BEST, as if it did something different, will  just confuses novice SAS users into thinking that it is somehow going to do something different than the normal numeric informat.&lt;BR /&gt;</description>
      <pubDate>Tue, 13 Mar 2018 03:25:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/445007#M28782</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-13T03:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Drop leading zeros from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/452853#M29217</link>
      <description>&lt;P&gt;First solution I tried and it worked like a charm.&amp;nbsp; &amp;nbsp;Thanks!!!!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 14:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/452853#M29217</guid>
      <dc:creator>RPYee</dc:creator>
      <dc:date>2018-04-10T14:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: Drop leading zeros from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/555976#M33630</link>
      <description>&lt;P&gt;This thread has been helpful.&amp;nbsp; I'm looking for something similar but my values contain some non digit characters.&amp;nbsp; How can I modify your solution to fit that criteria?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 15:27:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/555976#M33630</guid>
      <dc:creator>jquon126</dc:creator>
      <dc:date>2019-05-03T15:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: Drop leading zeros from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/556146#M33631</link>
      <description>&lt;P&gt;Please supply some examples for your character values, and what you expect as results.&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2019 03:52:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/556146#M33631</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-04T03:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: Drop leading zeros from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/556196#M33633</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272774"&gt;@jquon126&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This thread has been helpful.&amp;nbsp; I'm looking for something similar but my values contain some non digit characters.&amp;nbsp; How can I modify your solution to fit that criteria?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then use one of the other answers that can work on strings that are not representations of numbers.&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2019 16:35:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/556196#M33633</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-04T16:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: Drop leading zeros from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/656615#M36206</link>
      <description>&lt;P&gt;In SAS EG, create a calculated field--&lt;/P&gt;
&lt;P&gt;For Char to numeric&lt;/P&gt;
&lt;P&gt;INPUT(t1.'Ent Id Number'n,Z10.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Convert numeric Entity ID(for example, imported from a spreadsheet)&amp;nbsp; without leading zeroes to 10 Char with leading zeroes.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;From Numeric to Char&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;PUT(t1.'Entity ID'n,Z10.)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Best of luck!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2020 22:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-leading-zeros-from-character-variable/m-p/656615#M36206</guid>
      <dc:creator>JSJ</dc:creator>
      <dc:date>2020-06-10T22:54:43Z</dc:date>
    </item>
  </channel>
</rss>

