<?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 numeric data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/672672#M202180</link>
    <description>&lt;P&gt;Here's some sample code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data got ;
	infile cards ;
	input nVar cVar $ ;
	put nVar= cVar= ;
cards;
1.500 1.500
-0.400 -0.400
1.000 1.000
99.90 99.90
-99.90 -99.90 
;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When you run that you will get the follow in the log:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;35   data got ;
36       infile cards ;
37       input nVar cVar $ ;
38       put nVar= cVar= ;
39   cards;

nVar=1.5 cVar=1.500
nVar=-0.4 cVar=-0.400
nVar=1 cVar=1.000
nVar=99.9 cVar=99.90
nVar=-99.9 cVar=-99.90
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see the zeros are only kept in the character variable (cVar) and not in the numeric variable (nVar)&lt;/P&gt;</description>
    <pubDate>Mon, 27 Jul 2020 19:26:50 GMT</pubDate>
    <dc:creator>AMSAS</dc:creator>
    <dc:date>2020-07-27T19:26:50Z</dc:date>
    <item>
      <title>remove leading and trailing zeros from numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/672667#M202176</link>
      <description>&lt;P&gt;hi community,&lt;/P&gt;&lt;P&gt;what technique can i use to get rid of zeros in sas numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for eample, i have inputs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.500&lt;/P&gt;&lt;P&gt;-0.400&lt;/P&gt;&lt;P&gt;1.000&lt;/P&gt;&lt;P&gt;0.100&lt;/P&gt;&lt;P&gt;99.90&lt;/P&gt;&lt;P&gt;-99.90&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and need these outputs,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.5&lt;/P&gt;&lt;P&gt;-.4&lt;/P&gt;&lt;P&gt;1.0&lt;/P&gt;&lt;P&gt;.1&lt;/P&gt;&lt;P&gt;99.9&lt;/P&gt;&lt;P&gt;-99.9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what's the best way to do this?&lt;/P&gt;&lt;P&gt;all i want to do is remove the zeros from the numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;appreciate any help from the community on this.&lt;/P&gt;&lt;P&gt;thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 19:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/672667#M202176</guid>
      <dc:creator>mike24</dc:creator>
      <dc:date>2020-07-27T19:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: remove leading and trailing zeros from numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/672669#M202177</link>
      <description>SAS only stores the number without leading/trailing zeros, so unless this is a character variable then the zeros are not stored.&lt;BR /&gt;Having said that zeros could be displayed if it's a numeric variable and you have a format on it e.g. z10.5</description>
      <pubDate>Mon, 27 Jul 2020 19:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/672669#M202177</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2020-07-27T19:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: remove leading and trailing zeros from numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/672671#M202179</link>
      <description>&lt;P&gt;Are these numeric values or character strings? If numeric, try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;num2 = round(original_num, 0.1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If character strings, try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;num2 = round(input(original_num, 8.3), 0.1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 19:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/672671#M202179</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-07-27T19:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: remove leading and trailing zeros from numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/672672#M202180</link>
      <description>&lt;P&gt;Here's some sample code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data got ;
	infile cards ;
	input nVar cVar $ ;
	put nVar= cVar= ;
cards;
1.500 1.500
-0.400 -0.400
1.000 1.000
99.90 99.90
-99.90 -99.90 
;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When you run that you will get the follow in the log:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;35   data got ;
36       infile cards ;
37       input nVar cVar $ ;
38       put nVar= cVar= ;
39   cards;

nVar=1.5 cVar=1.500
nVar=-0.4 cVar=-0.400
nVar=1 cVar=1.000
nVar=99.9 cVar=99.90
nVar=-99.9 cVar=-99.90
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see the zeros are only kept in the character variable (cVar) and not in the numeric variable (nVar)&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 19:26:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/672672#M202180</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2020-07-27T19:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: remove leading and trailing zeros from numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/672673#M202181</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to display 1 decimal place then use a format that has .1 for the decimals:&lt;/P&gt;
&lt;PRE&gt;data junk;
   input x;
   put x= 6.1;
datalines;
1.500
-0.400
1.000
0.100
99.90
-99.90
;&lt;/PRE&gt;
&lt;P&gt;For example. If you want no zeroes for values between -1 and 1 you will have to spend some time working on a custom format that is also misleading to some extent. When ever I see a value like .4 is wonder what got left off.&amp;nbsp; The 0 in 0.4 is significant and for almost any real purpose should not be removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, what use case do you have that requires 0.4 to display as .4 where a leading 0 causes and error or actual problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 19:27:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/672673#M202181</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-27T19:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: remove leading and trailing zeros from numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/672675#M202183</link>
      <description>&lt;P&gt;Are your inputs character strings or numbers?&amp;nbsp; Do you want as output character strings or numbers?&lt;/P&gt;
&lt;P&gt;Note that SAS stores numbers as binary floating point. The string 000.5000 represents the exact same number as the string .5. Also note that floating point numbers cannot store every decimal representation exactly.&amp;nbsp; Values like .1 and .3 will be approximated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you clarify the rules?&lt;/P&gt;
&lt;P&gt;It looks like you want integers displayed with a period and zero in the tenths place.&lt;/P&gt;
&lt;P&gt;It is not clear what you want when the number is not an exact multiple of 1/10.&amp;nbsp; Do you want to display more digits after the decimal place?&amp;nbsp; Round to nearest tenth?&amp;nbsp; Truncate/floor to the tenth?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really have to remove the leading zero for values with absolute values less than 1? If not the just using the normal numeric display formats will work.&amp;nbsp; For example 10.1 will display one decimal place.&amp;nbsp; And BEST10.1 will remove the period and decimal place from integer values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;418   data test;
419     input string $10. @1 number ;
420     put string $10. +1 number 10.1 +1 number best10.1;
421   cards;

1.500             1.5        1.5
-0.400           -0.4       -0.4
1.000             1.0          1
0.100             0.1        0.1
99.90            99.9       99.9
-99.90          -99.9      -99.9
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 19:41:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/672675#M202183</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-27T19:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: remove leading and trailing zeros from numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/673112#M202430</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Thanks for the info.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 29 Jul 2020 13:31:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/673112#M202430</guid>
      <dc:creator>mike24</dc:creator>
      <dc:date>2020-07-29T13:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: remove leading and trailing zeros from numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/673119#M202432</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I ran the example, this helped out.&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Ni o attachments. -##</description>
      <pubDate>Wed, 29 Jul 2020 13:41:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/673119#M202432</guid>
      <dc:creator>mike24</dc:creator>
      <dc:date>2020-07-29T13:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: remove leading and trailing zeros from numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/673127#M202435</link>
      <description>Useful rounding mechanism...&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 29 Jul 2020 13:53:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/673127#M202435</guid>
      <dc:creator>mike24</dc:creator>
      <dc:date>2020-07-29T13:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: remove leading and trailing zeros from numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/673140#M202441</link>
      <description>Hi ballardw,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This helps out some, I went back and changed my program to use 10.1 numbers.&lt;BR /&gt;&lt;BR /&gt;These numbers are for simple display only.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I found a picture format in SAS 9.4 windows help, but I'm still studying it to see if it'll work for me.&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc format;&lt;BR /&gt;picture nozeros (fuzz=0)&lt;BR /&gt;low - -1 = '000.00' (prefix='-')&lt;BR /&gt;-1 &amp;lt; - &amp;lt; -.99 = '0.99' (prefix='-.' mult=100)&lt;BR /&gt;-0.99 &amp;lt;-&amp;lt; 0 = '99' (prefix='-.' mult=100)&lt;BR /&gt;0 = '9.99'&lt;BR /&gt;0 &amp;lt; -&amp;lt; .99 = '99' (prefix='.' mult=100)&lt;BR /&gt;0.99 - &amp;lt; 1 = '0.99' (prefix='.' mult=100)&lt;BR /&gt;1 - high = '09.99';&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 29 Jul 2020 14:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/673140#M202441</guid>
      <dc:creator>mike24</dc:creator>
      <dc:date>2020-07-29T14:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: remove leading and trailing zeros from numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/673158#M202449</link>
      <description>&lt;P&gt;So to adjust that for just a single decimal place you could use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture nozeros (fuzz=0)
   -1 &amp;lt; - &amp;lt; 0 = '9' (prefix='-.' mult=10)
    0  - &amp;lt; 1  = '9' (prefix='.' mult=10)
    other = [17.1]
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Make sure to round the values first.&amp;nbsp; Use the -L modifier on the format specification if you want the leading spaces removed.&lt;/P&gt;
&lt;PRE&gt;824   data test;
825     do i=-1234567,-123.456,-1,-.99,0,.1,.9999,1,1.1,1.234,123456789;
826        j=round(i,0.1);
827        put i best10. ' | ' i nozeros.-l @40 j best10. ' | ' j nozeros.-l ;
828     end;
829   run;

  -1234567 | -1234567.0                  -1234567 | -1234567.0
  -123.456 | -123.5                        -123.5 | -123.5
        -1 | -1.0                              -1 | -1.0
     -0.99 | -.9                               -1 | -1.0
         0 | .0                                 0 | .0
       0.1 | .1                               0.1 | .1
    0.9999 | .9                                 1 | 1.0
         1 | 1.0                                1 | 1.0
       1.1 | 1.1                              1.1 | 1.1
     1.234 | 1.2                              1.2 | 1.2
 123456789 | 123456789.0                123456789 | 123456789.0
&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jul 2020 15:02:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/673158#M202449</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-29T15:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: remove leading and trailing zeros from numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/673245#M202486</link>
      <description>Tom,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks for your help.&lt;BR /&gt;&lt;BR /&gt;The picture format you provided worked great!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 29 Jul 2020 18:06:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-leading-and-trailing-zeros-from-numeric-data/m-p/673245#M202486</guid>
      <dc:creator>mike24</dc:creator>
      <dc:date>2020-07-29T18:06:10Z</dc:date>
    </item>
  </channel>
</rss>

