<?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: convert character variable z4. to character variable without padding zero in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699879#M214107</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;today I was testing this solution but I've found a problem.&lt;/P&gt;&lt;P&gt;If the number is 0070 o 0700 I obtain 7 in both case but the first is supposed to be 70 and the second to be 700. I understand there is a mistake in my title because I just want remove leading zero.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines missover;
	input var1 $4.;
	datalines;
0700
0070
;
run;

data test;
	set have;
	*do as the title says;
	var2 = compress(var1,"0");
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Nov 2020 16:37:30 GMT</pubDate>
    <dc:creator>Ccasagran737</dc:creator>
    <dc:date>2020-11-18T16:37:30Z</dc:date>
    <item>
      <title>convert character variable z4. to character variable without padding zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699309#M213930</link>
      <description>&lt;P&gt;Hy!&lt;/P&gt;&lt;P&gt;As I've written in the subjet I need to convert a character variabile with padding zero in an another character variabile without padding zero.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've found this solution but I was wondering if there is an easier one.&lt;/P&gt;&lt;P&gt;Thans for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines missover;
	input var1 $4.;
	datalines;
0345
0002 
0032
;
run;

data want;
	set have;
	var2 = compress(put(input(var1,4.),3.));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Nov 2020 21:24:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699309#M213930</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2020-11-16T21:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: convert character variable z4. to character variable without padding zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699315#M213931</link>
      <description>&lt;P&gt;Not much improvement though&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;var2 = put(input(var1,4.),3. -L);&lt;/LI-CODE&gt;
&lt;P&gt;The -L with the Put function means to left justify the result, so compress or other space remover is not needed.&lt;/P&gt;
&lt;P&gt;However I would likely leave the Put format a 4. just in case you have some values that don't have the leading zero, or explicitly test for such.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 21:51:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699315#M213931</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-16T21:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: convert character variable z4. to character variable without padding zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699339#M213938</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175761"&gt;@Ccasagran737&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175761"&gt;@Ccasagran737&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I've found this solution but I was wondering if there is an easier one.&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If (by "easier") you mean "shorter code," you could go two steps further:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You could replace &lt;FONT face="courier new,courier"&gt;put(..., 3.-L)&lt;/FONT&gt; with &lt;FONT face="courier new,courier"&gt;cat(...)&lt;/FONT&gt;, but then the default length of &lt;FONT face="courier new,courier"&gt;var2&lt;/FONT&gt; would be 200 rather than 3. I would not recommend this.&lt;/LI&gt;
&lt;LI&gt;There are "brute" coders who don't mind notes about automatic character-to-numeric conversion in the log, nor the ugliness of a character variable in an arithmetic expression (cf.&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lepg&amp;amp;docsetTarget=n1gdn9fqqrjbwin1prm30gcpobco.htm&amp;amp;locale=en#n1remvp377lmyxn1070yon4d8qod" target="_blank" rel="noopener"&gt;Automatic Character-to-Numeric Conversion&lt;/A&gt;). So you could get the result without using the INPUT function (i.e., the clean, recommended method for character-to-numeric conversion), but I refuse to write such ugly code.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 17 Nov 2020 00:26:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699339#M213938</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-11-17T00:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: convert character variable z4. to character variable without padding zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699340#M213939</link>
      <description>&lt;P&gt;If var1 is always 4 non-blank characters with at least one leading zero, as in your sample data, then just take a substr of var1, starting at the 2nd character:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines missover;
	input var1 $4.;
	datalines;
0345
0002 
0032
run;

data want;
	set have;
	length var2 $3;
	var2 = substr(var1,2);
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>Tue, 17 Nov 2020 00:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699340#M213939</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-11-17T00:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: convert character variable z4. to character variable without padding zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699344#M213941</link>
      <description>&lt;P&gt;why not do as the title says?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines missover;
	input var1 $4.;
	datalines;
0345
0002 
0032
;
run;

data want;
	set have;
	*do as the title says;
	var2 = compress(var1,"0");
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Nov 2020 01:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699344#M213941</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-11-17T01:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: convert character variable z4. to character variable without padding zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699394#M213957</link>
      <description>Thank everyone for helping me!!!</description>
      <pubDate>Tue, 17 Nov 2020 08:18:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699394#M213957</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2020-11-17T08:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: convert character variable z4. to character variable without padding zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699396#M213958</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175761"&gt;@Ccasagran737&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just to be sure: Do you really want to map, e.g., &lt;FONT face="courier new,courier"&gt;'0305'&lt;/FONT&gt;&amp;nbsp;(as well as &lt;FONT face="courier new,courier"&gt;'0035'&lt;/FONT&gt;) to &lt;FONT face="courier new,courier"&gt;'35'&lt;/FONT&gt;&amp;nbsp;(which is what the COMPRESS function would do)?&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 08:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699396#M213958</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-11-17T08:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: convert character variable z4. to character variable without padding zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699466#M213971</link>
      <description>&lt;PRE&gt;data have;
	infile datalines missover;
	input var1 $4.;
	datalines;
0345
0002 
0032
;
run;
data want;
	set have;
	var2 = prxchange('s/^0+//',-1,var1);
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Nov 2020 12:39:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699466#M213971</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-11-17T12:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: convert character variable z4. to character variable without padding zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699879#M214107</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;today I was testing this solution but I've found a problem.&lt;/P&gt;&lt;P&gt;If the number is 0070 o 0700 I obtain 7 in both case but the first is supposed to be 70 and the second to be 700. I understand there is a mistake in my title because I just want remove leading zero.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines missover;
	input var1 $4.;
	datalines;
0700
0070
;
run;

data test;
	set have;
	*do as the title says;
	var2 = compress(var1,"0");
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 16:37:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/699879#M214107</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2020-11-18T16:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: convert character variable z4. to character variable without padding zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/700030#M214192</link>
      <description>&lt;P&gt;I'm sorry.&lt;BR /&gt;I only read the title and made that answer.&lt;BR /&gt;KSharp sent me an excellent solution of using prxchange function.&lt;BR /&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;.&lt;BR /&gt;Other than prxchange function, there is a verify function that returns the position of the first character in source that is not present.&lt;BR /&gt;Combined with substr function, it can remove leading zeroes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines missover;
	input var1 $4.;
	datalines;
0700
0070
;
run;

data want;
	set have;
	*remove leading blank by regular expression;
	var2=prxchange("s/^0+//i",-1,var1);
	*VERIFY function returns the position of the first character in source that is not present;
	var3=substr(var1,verify(var1,"0"));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Nov 2020 22:53:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-variable-z4-to-character-variable-without/m-p/700030#M214192</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-11-18T22:53:42Z</dc:date>
    </item>
  </channel>
</rss>

