<?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 remove leading zeroes from character variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51710#M14199</link>
    <description>do&lt;BR /&gt;
&lt;BR /&gt;
id1=id*1&lt;BR /&gt;
then if u wnat use the id1 or u can convert id1 again in to character.&lt;BR /&gt;
id1=put(id1,char4.);</description>
    <pubDate>Mon, 19 Jul 2010 09:34:50 GMT</pubDate>
    <dc:creator>sas_</dc:creator>
    <dc:date>2010-07-19T09:34:50Z</dc:date>
    <item>
      <title>How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51703#M14192</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I Have a character variable with comes with leading zeroes.&lt;BR /&gt;
&lt;BR /&gt;
ID&lt;BR /&gt;
0111&lt;BR /&gt;
0222&lt;BR /&gt;
0333&lt;BR /&gt;
&lt;BR /&gt;
my desired result:&lt;BR /&gt;
ID&lt;BR /&gt;
111&lt;BR /&gt;
222&lt;BR /&gt;
333&lt;BR /&gt;
&lt;BR /&gt;
Please help</description>
      <pubDate>Fri, 16 Jul 2010 19:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51703#M14192</guid>
      <dc:creator>ren2010</dc:creator>
      <dc:date>2010-07-16T19:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51704#M14193</link>
      <description>DATA step, assignment statement using the INPUT function to convert your character variable to a SAS numeric variable, then use the desired SAS output format for the numeric variable (or take the SAS-default assigned).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
convert character numeric variable input function site:sas.com</description>
      <pubDate>Fri, 16 Jul 2010 19:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51704#M14193</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-07-16T19:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51705#M14194</link>
      <description>&lt;P&gt;&lt;EM&gt;Editor's note: The INPUT ifunction is the easist solution first mentioned by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13636"&gt;@sbb﻿&lt;/a&gt;.&amp;nbsp; Cynthia goes into a little more detail below on the solution.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi:&lt;BR /&gt; Remember that there may be a reason that an ID number has a leading zero. It could be that the ID will be invalid without the leading zero.&lt;BR /&gt; &lt;BR /&gt; It would be useful to know whether you want to create a new numeric variable without leading zeroes (easily done with the INPUT function); or whether you want to create a new character variable (still possible, but needs to use both the PUT and INPUT functions).&lt;BR /&gt; &lt;BR /&gt; In the conversion of a character string using the &lt;A href="https://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#p19en16vskd2vhn1vwmxpxnglxxs.htm" target="_self"&gt;INPUT function&lt;/A&gt;, leading zeroes automatically "go away". Once you have a new numeric variable, you might be satisfied with that value as a number. On the other hand, if you really just want a new character variable, then you can take the results of the INPUT function and use the PUT function to turn the new number back into a character string. If you want the value "left-justified", then either the COMPRESS function or the LEFT function would get rid of leading spaces in the new character string. In my example below, I use the LEFT function with the PUT function. (I added some test cases to the data to show that the 2 methods will work for a broader range of data scenarios.)&lt;BR /&gt; &lt;BR /&gt; cynthia&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data charval;
 infile datalines;
 input ID $;
 ** create a numeric variable which will not contain a leading 0;
 ** the INPUT function turns a character string into a number value;
 newnum = input(ID,4.);

 ** The INPUT and PUT function together would correctly make a;
 ** new character variable without leading zeroes;
 newchar_fromPUT = left(put(newnum,$4.));

 return;
 datalines;
 0111
 0222
 0333
 0404
 5348
 0044
 ;
 

options nodate nonumber;
 proc print data=charval;
   var ID newnum newchar_fromPUT;
   title 'Get Rid of -ONLY- the Leading Zero in ID Char String';
   title2 'INPUT method makes a numeric variable';
   title3 'PUT with INPUT makes a character variable';
 run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2016 15:41:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51705#M14194</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-09-22T15:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51706#M14195</link>
      <description>Assuming that you do want a character variable without leading zeros, an alternative to the PUT INPUT functions could be the use of the VERIFY and SUBSTR functions.   Not because they are better but VERIFY does not get used too much and here is its chance to shine.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data val;&lt;BR /&gt;
x='000asd1234';output;&lt;BR /&gt;
x='123'; output;&lt;BR /&gt;
x='0009876'; output;&lt;BR /&gt;
run;&lt;BR /&gt;
data nozero;&lt;BR /&gt;
   set val;&lt;BR /&gt;
   y = substr(x,verify(x,'0'));&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Sat, 17 Jul 2010 22:54:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51706#M14195</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-07-17T22:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51707#M14196</link>
      <description>Use the INPUT function to ensure an accurate result (based on the original data sample posted).  No question that VERIFY has its purpose but definitely not here - considering an embedded zero character in the character variable string.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sun, 18 Jul 2010 14:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51707#M14196</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-07-18T14:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51708#M14197</link>
      <description>VERIFY returns position of first character NOT in the second argument.  Embedded zero is not a problem.</description>
      <pubDate>Sun, 18 Jul 2010 14:44:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51708#M14197</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-07-18T14:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51709#M14198</link>
      <description>I stand corrected - nice application, ArtC.&lt;BR /&gt;
&lt;BR /&gt;
Scott</description>
      <pubDate>Sun, 18 Jul 2010 15:00:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51709#M14198</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-07-18T15:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51710#M14199</link>
      <description>do&lt;BR /&gt;
&lt;BR /&gt;
id1=id*1&lt;BR /&gt;
then if u wnat use the id1 or u can convert id1 again in to character.&lt;BR /&gt;
id1=put(id1,char4.);</description>
      <pubDate>Mon, 19 Jul 2010 09:34:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51710#M14199</guid>
      <dc:creator>sas_</dc:creator>
      <dc:date>2010-07-19T09:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51711#M14200</link>
      <description>A big THANK YOU to all of you for your suggestions,appreciate it.</description>
      <pubDate>Mon, 19 Jul 2010 16:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51711#M14200</guid>
      <dc:creator>ren2010</dc:creator>
      <dc:date>2010-07-19T16:51:19Z</dc:date>
    </item>
    <item>
      <title>How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51712#M14201</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was doing a google search to find the answer to my SAS problem, and found this question and answer.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know this posting is more than 1.5 years old, but I just wanted to say tha your answer is exactly what I needed and I thank you. My data is a character string of mixed numbers and letters almost like your first example, and I needed to drop the leading zeros.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Oh&amp;nbsp; I also want to thank ren2010 for posting the question in the first place.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Larry- &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Mar 2012 17:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51712#M14201</guid>
      <dc:creator>lordlnyc</dc:creator>
      <dc:date>2012-03-06T17:37:29Z</dc:date>
    </item>
    <item>
      <title>How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51713#M14202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are always a couple of ways&amp;nbsp; to solve a problem in SAS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data val;
x='000asd1234';output;
x='123'; output;
x='0009876'; output;
run;

data nozero;
&amp;nbsp;&amp;nbsp; set val;
&amp;nbsp;&amp;nbsp; y =prxchange('s/^0+//o',-1,x);
&amp;nbsp;&amp;nbsp; run;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Mar 2012 03:03:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51713#M14202</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-03-07T03:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51714#M14203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just wanted to shout out to Art C.&amp;nbsp; I hadn't used the verify function before, but I applied it much the way you did in your example to achieve exactly what I needed.&amp;nbsp; Also, love your book on Innovative SAS Techniques!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Jul 2014 17:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/51714#M14203</guid>
      <dc:creator>WilliamD_</dc:creator>
      <dc:date>2014-07-02T17:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/225622#M53952</link>
      <description>&lt;P&gt;&lt;SPAN class="hps"&gt;I do it&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;that way.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA FINAL;
	SET ORIGEM;

	TEST = COMPRESS(PUT(INPUT(VARIABLE_WITH_ZERO,8.),8.));

RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;8. is the size of the variable.&lt;/P&gt;&lt;P&gt;Compress is for remove blank spaces.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 15:24:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/225622#M53952</guid>
      <dc:creator>osvaldoberg</dc:creator>
      <dc:date>2015-09-15T15:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/225740#M53967</link>
      <description>&lt;P&gt;Hi, try this ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data x;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input id :$6. @@;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;0111 0222 0333 000012 0099 88&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data xplus;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set x;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;id = cat(input(id,6.));&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;data set XPLUS&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;Obs id&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;1 &amp;nbsp; 111&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;2 &amp;nbsp; 222&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;3 &amp;nbsp; 333&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;4 &amp;nbsp; 12&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;5 &amp;nbsp; 99&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;6 &amp;nbsp; 88&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 23:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/225740#M53967</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2015-09-15T23:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove leading zeroes from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/225852#M53982</link>
      <description>&lt;P&gt;Brilliant!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2015 14:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-remove-leading-zeroes-from-character-variable/m-p/225852#M53982</guid>
      <dc:creator>SGK</dc:creator>
      <dc:date>2015-09-16T14:52:21Z</dc:date>
    </item>
  </channel>
</rss>

