<?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 leading and trailing zeros from character field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/945348#M370391</link>
    <description>&lt;P&gt;You don't need to learn any non-SAS skills, like regular expressions, to solve this and you don't need reams of code. The easiest way to deal with the endings of strings is to use reverse with strip (or trim) and the eventual solution code will need less conditions/statements.&lt;/P&gt;
&lt;P&gt;The "sample" input includes 00000 (mentioned in another reply).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;data test;
input textchar : $5.;
cards;
00000
00100
00101
01010
10100
10101
;
run;

data want;
  set test;
  length want $5;
  want=textchar;
	do while (substr(strip(reverse(want)),1,1) eq "0");
		want=strip(reverse(substr(strip(reverse(want)),2)));
	end;
run;

proc print;run;&lt;/PRE&gt;
&lt;P&gt;The result is:&lt;/P&gt;
&lt;DIV&gt;
&lt;TABLE class="table" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt; &lt;COL class="rowheader" /&gt; &lt;COL class="data" /&gt; &lt;COL class="data" /&gt; &lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="header" scope="colgroup"&gt;Obs&lt;/TH&gt;
&lt;TH class="header" scope="colgroup"&gt;textchar&lt;/TH&gt;
&lt;TH class="header" scope="colgroup"&gt;want&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;1&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;00000&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;2&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;00100&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;001&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;3&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;00101&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;00101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;4&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;01010&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;0101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;5&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;10100&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;6&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;10101&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;10101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;P&gt;Note: This is a solution based on my interpretation of the requirement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The alternative "do" loop construct (still based on the above):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do until (substr(strip(reverse(want)),1,1) ne "0");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;does &lt;STRONG&gt;not&lt;/STRONG&gt; work - observations 3 and 6 are incorrect:&lt;/P&gt;
&lt;DIV&gt;
&lt;TABLE class="table" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt; &lt;COL class="rowheader" /&gt; &lt;COL class="data" /&gt; &lt;COL class="data" /&gt; &lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="header" scope="colgroup"&gt;Obs&lt;/TH&gt;
&lt;TH class="header" scope="colgroup"&gt;textchar&lt;/TH&gt;
&lt;TH class="header" scope="colgroup"&gt;want&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;1&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;00000&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;2&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;00100&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;001&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;3&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;00101&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier" color="#FF0000"&gt;00101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;4&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;01010&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;0101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;5&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;10100&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;6&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;10101&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier" color="#FF0000"&gt;10101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 26 Sep 2024 16:53:57 GMT</pubDate>
    <dc:creator>ishmo65</dc:creator>
    <dc:date>2024-09-26T16:53:57Z</dc:date>
    <item>
      <title>Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124921#M260079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Is there an easier way?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;data test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Input textchar : $5.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;cards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;00100&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;00101&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;01010&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;10100&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;10101&lt;/SPAN&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;data want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; set test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;new1 = tranwrd(textchar, "0", " ");&amp;nbsp;&amp;nbsp; /* replace zeros with spaces */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;new2 = substr(new1, verify(new1,' ')) /* remove spaces&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;new3 = tranwrd(new2&amp;nbsp;&amp;nbsp;&amp;nbsp; , " ", "0");&amp;nbsp;&amp;nbsp; /* replace spaces with zeros */&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;new4 = substr(new3, 1, length(new2)); /* remove trailing zeros&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2012 17:49:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124921#M260079</guid>
      <dc:creator>csc</dc:creator>
      <dc:date>2012-11-13T17:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124922#M260080</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; want = tranwrd(strip(tranwrd(textchar, "0", " "))," ","0");&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2012 18:25:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124922#M260080</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-11-13T18:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124923#M260081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know if this is easier, it is your call:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Input&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; textchar : &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: teal; background: white;"&gt;$5.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;00100&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;00101&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;01010&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;10100&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;10101&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;length&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; want $&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;5&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; want=prxchange(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"s/(0+$)//"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,-&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,strip(prxchange(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"s/(^0+)//"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;, -&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,textchar)));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;print&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;Haikuo &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2012 18:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124923#M260081</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-11-13T18:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124924#M260082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;Input textchar : $5.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;00100&lt;/P&gt;&lt;P&gt;00101&lt;/P&gt;&lt;P&gt;01010&lt;/P&gt;&lt;P&gt;10100&lt;/P&gt;&lt;P&gt;10101&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data temp;&lt;/P&gt;&lt;P&gt; length new $ 5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; n=put(input(textchar,5.),5.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; new=ifc(substr(n,length(n),1) ne '0',n,substr(n,1,length(n)-length(scan(n,-1,"123456789"))));&lt;/P&gt;&lt;P&gt; drop n;&lt;/P&gt;&lt;P&gt;proc print;run;:smileysilly::smileysilly::smileysilly:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2012 18:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124924#M260082</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-11-13T18:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124925#M260083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do we have an item for the SASWare Ballot here?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;textchar = strip(textchar, '0');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anybody else have a use for this type of functionality?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that some posted solutions work differently than others when the incoming string is 00000.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2012 19:16:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124925#M260083</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-11-13T19:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124926#M260084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another prx solution, handling the "00000" separately.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Consolas, Courier New; font-size: 90%; line-height: 1.1;"&gt;&lt;SPAN style="color: #0000ff;"&gt;ods&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;_all_&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;close&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #0000ff;"&gt;ods&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;listing&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #0000ff;"&gt;options&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;nocenter&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;STRONG style="color: #000080;"&gt;data&lt;/STRONG&gt;&lt;SPAN&gt; test;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;Input&lt;/SPAN&gt;&lt;SPAN&gt; textchar : &lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;$5.&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #0000ff;"&gt;cards&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;00100&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;00101&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;01010&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;10100&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;10101&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;11111&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;10001&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;00011&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;11000&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;00000&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;STRONG style="color: #000080;"&gt;run&lt;/STRONG&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;STRONG style="color: #000080;"&gt;data&lt;/STRONG&gt;&lt;SPAN&gt; chang;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;set&lt;/SPAN&gt;&lt;SPAN&gt; test;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;length&lt;/SPAN&gt;&lt;SPAN&gt; new4 $&lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;5&lt;/STRONG&gt;&lt;SPAN&gt;; &lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; textchar = &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;"00000"&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;then&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; new4 = &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;"0"&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;else&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; new4 = prxchange(&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;"s|^0*(.*?)0*$|$1|"&lt;/SPAN&gt;&lt;SPAN&gt;, -&lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;1&lt;/STRONG&gt;&lt;SPAN&gt;, textchar);&lt;/SPAN&gt;&lt;BR /&gt; &lt;STRONG style="color: #000080;"&gt;run&lt;/STRONG&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;STRONG style="color: #000080;"&gt;proc&lt;/STRONG&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;STRONG style="color: #000080;"&gt;print&lt;/STRONG&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;data&lt;/SPAN&gt;&lt;SPAN&gt;=chang;&lt;/SPAN&gt;&lt;BR /&gt; &lt;STRONG style="color: #000080;"&gt;run&lt;/STRONG&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;/* on lst&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp; textchar&amp;nbsp;&amp;nbsp;&amp;nbsp; new4&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 00100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 00101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 101&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01010&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 101&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 101&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10101&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11111&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11111&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10001&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt; 8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 00011&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt; 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 00000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2012 19:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124926#M260084</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2012-11-13T19:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124927#M260085</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through; font-family: mceinline;"&gt;@Astounding: if so, then the strip would return "101", when the input was "10001," wouldn't it?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through; font-family: mceinline;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;@Art: Thanks for the correction. I've got confused. Astounding and you are absolutely correct. &lt;SPAN&gt;strip(&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;...&lt;/SPAN&gt;&lt;SPAN&gt;) &lt;/SPAN&gt; is equivalent to &lt;SPAN&gt;trimn(left(&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;...&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2012 19:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124927#M260085</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2012-11-13T19:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124928#M260086</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Put it in.&amp;nbsp; I'll vote for it!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2012 19:26:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124928#M260086</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-11-13T19:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124929#M260087</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Chang, No, strip only removes leading and trailing blanks (or, in this case, specific leading and trailing characters).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2012 19:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124929#M260087</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-11-13T19:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124930#M260088</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for all your input.&amp;nbsp; The reason it remains "Not Answered" is I have no icons to mark "Correct" or "Helpful".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 15:43:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124930#M260088</guid>
      <dc:creator>csc</dc:creator>
      <dc:date>2012-12-06T15:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124931#M260089</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A __default_attr="574853" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt; You must have been logged in when you were on the page, but others have faced the same problem before and I don't think anyone has yet discovered why that happens sometimes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A __default_attr="15755" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;: Renee, Do you know why people sometime don't get to see the correct and helpful icons when they do have a post marked as a question and are logged on?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 21:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124931#M260089</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-12-06T21:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124932#M260090</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know how this happens. I can't reproduce the experience, so it is hard to debug.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have been working with the Jive tech support staff.&amp;nbsp; They suggested that we verify the the post was opened as a question -- this one was. And that the person who is trying to mark it as helpful verify that they are actively logged in (refresh the page to make sure your log in hasn't expired).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The other option for @Csc to try is to select Reply on the answer they want to mark as correct.&amp;nbsp; It should also show up then.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd love to hear from you if either of these things work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 21:37:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/124932#M260090</guid>
      <dc:creator>reneeharper</dc:creator>
      <dc:date>2012-12-06T21:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/285854#M260091</link>
      <description>&lt;P&gt;I did try your code,&lt;/P&gt;
&lt;P&gt;ERROR 72-185: The STRIP function call has too many arguments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 15:54:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/285854#M260091</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2016-07-20T15:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/370752#M260092</link>
      <description>&lt;P&gt;This method was SO much simpler than anything out there. I tried so many different variations but could not find something to remove the leading zeros and keep the other zeros in an account number....this was perfect! Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 20:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/370752#M260092</guid>
      <dc:creator>Michele_E76</dc:creator>
      <dc:date>2017-06-26T20:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/370771#M260093</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Put it in. I'll vote for it.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 22:56:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/370771#M260093</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-06-26T22:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/945348#M370391</link>
      <description>&lt;P&gt;You don't need to learn any non-SAS skills, like regular expressions, to solve this and you don't need reams of code. The easiest way to deal with the endings of strings is to use reverse with strip (or trim) and the eventual solution code will need less conditions/statements.&lt;/P&gt;
&lt;P&gt;The "sample" input includes 00000 (mentioned in another reply).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;data test;
input textchar : $5.;
cards;
00000
00100
00101
01010
10100
10101
;
run;

data want;
  set test;
  length want $5;
  want=textchar;
	do while (substr(strip(reverse(want)),1,1) eq "0");
		want=strip(reverse(substr(strip(reverse(want)),2)));
	end;
run;

proc print;run;&lt;/PRE&gt;
&lt;P&gt;The result is:&lt;/P&gt;
&lt;DIV&gt;
&lt;TABLE class="table" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt; &lt;COL class="rowheader" /&gt; &lt;COL class="data" /&gt; &lt;COL class="data" /&gt; &lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="header" scope="colgroup"&gt;Obs&lt;/TH&gt;
&lt;TH class="header" scope="colgroup"&gt;textchar&lt;/TH&gt;
&lt;TH class="header" scope="colgroup"&gt;want&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;1&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;00000&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;2&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;00100&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;001&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;3&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;00101&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;00101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;4&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;01010&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;0101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;5&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;10100&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;6&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;10101&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;10101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;P&gt;Note: This is a solution based on my interpretation of the requirement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The alternative "do" loop construct (still based on the above):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do until (substr(strip(reverse(want)),1,1) ne "0");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;does &lt;STRONG&gt;not&lt;/STRONG&gt; work - observations 3 and 6 are incorrect:&lt;/P&gt;
&lt;DIV&gt;
&lt;TABLE class="table" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt; &lt;COL class="rowheader" /&gt; &lt;COL class="data" /&gt; &lt;COL class="data" /&gt; &lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="header" scope="colgroup"&gt;Obs&lt;/TH&gt;
&lt;TH class="header" scope="colgroup"&gt;textchar&lt;/TH&gt;
&lt;TH class="header" scope="colgroup"&gt;want&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;1&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;00000&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;2&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;00100&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;001&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;3&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;00101&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier" color="#FF0000"&gt;00101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;4&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;01010&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;0101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;5&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;10100&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;6&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier"&gt;10101&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="b data"&gt;&lt;FONT face="courier new,courier" color="#FF0000"&gt;10101&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 16:53:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/945348#M370391</guid>
      <dc:creator>ishmo65</dc:creator>
      <dc:date>2024-09-26T16:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: Remove leading and trailing zeros from character field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/945393#M370401</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;data want;
	set test;
	format z_char $5.;

	/* Remove leading */
	z_char=strip(put(input(strip(textchar), 5.), 5.));

	/* Remove trailing */
	P=findc(z_char, "0", 'K', -length(z_char)); 
	 if P then Y = substr(z_char, 1, P); 

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Sep 2024 23:19:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-leading-and-trailing-zeros-from-character-field/m-p/945393#M370401</guid>
      <dc:creator>help_me_i_dumb</dc:creator>
      <dc:date>2024-09-26T23:19:33Z</dc:date>
    </item>
  </channel>
</rss>

