<?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: Removing leading zeros from character with symbols in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-leading-zeros-from-character-with-symbols/m-p/665849#M199142</link>
    <description>&lt;P&gt;Here's one way to do it, using INPUT() to remove leading zeros:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input variable $20.;
    datalines;
    1111-2020-00555
    1111-2021-546
    1111-2020-00789
    1111-2020-01234
    1111-2020-343
    ;
run;

data want (drop=last_dash);
    set have;
    last_dash = length(variable) - length(scan(variable,-1,'-'));
    new_variable = substr(variable,1,last_dash) || left(put(input(substr(variable,last_dash),best.),$20.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or another method, using VERIFY():&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=last_dash);
    set have;
    last_dash = length(variable) - length(scan(variable,-1,'-'));
    new_variable2 = substr(variable,1,last_dash) || substr(substr(variable,last_dash+1),verify(substr(variable,last_dash+1),'0'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 29 Jun 2020 17:13:32 GMT</pubDate>
    <dc:creator>mklangley</dc:creator>
    <dc:date>2020-06-29T17:13:32Z</dc:date>
    <item>
      <title>Removing leading zeros from character with symbols</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-leading-zeros-from-character-with-symbols/m-p/665833#M199137</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking for a SAS code to remove the trailing 0's from the end of a character, where it applies.&amp;nbsp; Please see the following as an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Have&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1111-2020-00555&lt;/P&gt;&lt;P&gt;1111-2021-546&lt;/P&gt;&lt;P&gt;1111-2020-00789&lt;/P&gt;&lt;P&gt;1111-2020-01234&lt;/P&gt;&lt;P&gt;1111-2020-343&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Want:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1111-2020-555&lt;/P&gt;&lt;P&gt;1111-2021-546&lt;/P&gt;&lt;P&gt;1111-2020-789&lt;/P&gt;&lt;P&gt;1111-2020-1234&lt;/P&gt;&lt;P&gt;1111-2020-343&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 16:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-leading-zeros-from-character-with-symbols/m-p/665833#M199137</guid>
      <dc:creator>DSAS_er</dc:creator>
      <dc:date>2020-06-29T16:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Removing leading zeros from character with symbols</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-leading-zeros-from-character-with-symbols/m-p/665845#M199140</link>
      <description>&lt;P&gt;Did you by chance create this variable using CATX()? If so, you could fix it in that step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

want = catx('-', input(scan(have, 1, "-"), 8.), input(scan(have, 2, "-"), 8.), input(scan(have, 3, "-"), 8.));

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/335810"&gt;@DSAS_er&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm looking for a SAS code to remove the trailing 0's from the end of a character, where it applies.&amp;nbsp; Please see the following as an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Have&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1111-2020-00555&lt;/P&gt;
&lt;P&gt;1111-2021-546&lt;/P&gt;
&lt;P&gt;1111-2020-00789&lt;/P&gt;
&lt;P&gt;1111-2020-01234&lt;/P&gt;
&lt;P&gt;1111-2020-343&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Want:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1111-2020-555&lt;/P&gt;
&lt;P&gt;1111-2021-546&lt;/P&gt;
&lt;P&gt;1111-2020-789&lt;/P&gt;
&lt;P&gt;1111-2020-1234&lt;/P&gt;
&lt;P&gt;1111-2020-343&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 16:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-leading-zeros-from-character-with-symbols/m-p/665845#M199140</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-29T16:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: Removing leading zeros from character with symbols</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-leading-zeros-from-character-with-symbols/m-p/665846#M199141</link>
      <description>&lt;P&gt;You need to provide a consistent RULE.&lt;/P&gt;
&lt;P&gt;I can write code that matches your example but probably will not work for any other values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And why does your subject line say "leading zeroes" and the description in body say "trailing zeroes"???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I might guess this would work:&lt;/P&gt;
&lt;PRE&gt;data have;
   input x :$15.;
datalines;
1111-2020-00555
1111-2021-546
1111-2020-00789
1111-2020-01234
1111-2020-343
;

data want;
   set have;
   x=cats(substr(x,1,10),input(substr(x,11),best.));
run;&lt;/PRE&gt;
&lt;P&gt;Please note the data step to provide example data. Without an actual example with properties of the variable we have to make guesses. And please post code or data in a code box opened with the &amp;lt;/&amp;gt; icon on the forum. The main message window will remove stuff and insert html codes. Sometimes what you paste is not what you expect and code won't work against it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider my "example" below:&lt;/P&gt;
&lt;PRE&gt;Have    Want
1           3
2           3
3           5
4           4
5           4
6           3&lt;/PRE&gt;
&lt;P&gt;Can you tell that the result for 7 should be 5, or that 21 should be 9?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 16:40:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-leading-zeros-from-character-with-symbols/m-p/665846#M199141</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-29T16:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: Removing leading zeros from character with symbols</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-leading-zeros-from-character-with-symbols/m-p/665849#M199142</link>
      <description>&lt;P&gt;Here's one way to do it, using INPUT() to remove leading zeros:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input variable $20.;
    datalines;
    1111-2020-00555
    1111-2021-546
    1111-2020-00789
    1111-2020-01234
    1111-2020-343
    ;
run;

data want (drop=last_dash);
    set have;
    last_dash = length(variable) - length(scan(variable,-1,'-'));
    new_variable = substr(variable,1,last_dash) || left(put(input(substr(variable,last_dash),best.),$20.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or another method, using VERIFY():&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=last_dash);
    set have;
    last_dash = length(variable) - length(scan(variable,-1,'-'));
    new_variable2 = substr(variable,1,last_dash) || substr(substr(variable,last_dash+1),verify(substr(variable,last_dash+1),'0'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 17:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-leading-zeros-from-character-with-symbols/m-p/665849#M199142</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-06-29T17:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: Removing leading zeros from character with symbols</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-leading-zeros-from-character-with-symbols/m-p/665854#M199143</link>
      <description>&lt;P&gt;Is this what you are looking for ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input str : $16.;
cards;
1111-2020-00555
1111-2021-546
1111-2020-00789
1111-2020-01234
1111-2020-343
;
run;

data want;
	set have;

	str=prxchange('s/-0+/-/io',-1,str);

	put (_all_) (=);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;28         data want;
29         	set have;
30         
31         	str=prxchange('s/-0+/-/io',1,str);
32         
33         	put (_all_) (=);
34         run;


str=1111-2020-555
str=1111-2021-546
str=1111-2020-789
str=1111-2020-1234
str=1111-2020-343&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jun 2020 17:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-leading-zeros-from-character-with-symbols/m-p/665854#M199143</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2020-06-29T17:19:06Z</dc:date>
    </item>
  </channel>
</rss>

