<?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: Trailing zeros in numeric variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Trailing-zeros-in-numeric-variable/m-p/601023#M173803</link>
    <description>&lt;P&gt;Are you sure the variable is a number and not a character string?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, you cannot store more than 15 or so decimal places in a number in SAS.&amp;nbsp; SAS stores all numbers as floating point.&amp;nbsp; You can use CONSTANT() function to see what is the largest integer that can be stored exactly.&lt;/P&gt;
&lt;PRE&gt;174   data _null_;
175    max=constant('exactint');
176    put max= comma32.;
177   run;

max=9,007,199,254,740,992&lt;/PRE&gt;
&lt;P&gt;So convert it to character. Or split it into two or more numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 01 Nov 2019 16:46:44 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-11-01T16:46:44Z</dc:date>
    <item>
      <title>Trailing zeros in numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trailing-zeros-in-numeric-variable/m-p/601009#M173796</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with a secondary dataset that includes a rather complicated&amp;nbsp;variable where some levels&amp;nbsp;have&amp;nbsp;many trailing zeros.&amp;nbsp;For some reason, not all levels are&amp;nbsp;included when&amp;nbsp;I create a new variable based on the original variable levels. For example, one of the levels for the variable is 1020405100000 (n=16). But when I try to test the creation of a new variable based just on this value using the code below, it does not display the appropriate output of 16. Rather it says "level=0." This pattern continues for levels for this variable that include trailing zeros. However,&amp;nbsp;if I&amp;nbsp;insert&amp;nbsp;shorter levels of the variable&amp;nbsp;such as 1110 (n=20) in the below code, the new variable accurately reflects n=20.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if q12=1020405100000 then newvar=1;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It was suggested that I attempt to truncate the variable to see this would&amp;nbsp;solve the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;So instead of having:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 1020405100000&lt;/P&gt;&lt;P&gt;2 10304051000000000&lt;/P&gt;&lt;P&gt;....;&lt;/P&gt;&lt;P&gt;It would be:&lt;/P&gt;&lt;P&gt;1 102040510&lt;/P&gt;&lt;P&gt;2 103040510&lt;/P&gt;&lt;P&gt;...;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you think this would solve the issue? If so, how is the best way to truncate the variable and remove the trailing zeros?&lt;/P&gt;&lt;P&gt;Thank you for any help.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2019 16:17:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trailing-zeros-in-numeric-variable/m-p/601009#M173796</guid>
      <dc:creator>sfw_09</dc:creator>
      <dc:date>2019-11-01T16:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: Trailing zeros in numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trailing-zeros-in-numeric-variable/m-p/601020#M173800</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SUBSTRN(PUT(num_val, 20.), -1, 11)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you tried SUBSTRN function yet?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2019 16:42:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trailing-zeros-in-numeric-variable/m-p/601020#M173800</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-11-01T16:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: Trailing zeros in numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trailing-zeros-in-numeric-variable/m-p/601023#M173803</link>
      <description>&lt;P&gt;Are you sure the variable is a number and not a character string?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, you cannot store more than 15 or so decimal places in a number in SAS.&amp;nbsp; SAS stores all numbers as floating point.&amp;nbsp; You can use CONSTANT() function to see what is the largest integer that can be stored exactly.&lt;/P&gt;
&lt;PRE&gt;174   data _null_;
175    max=constant('exactint');
176    put max= comma32.;
177   run;

max=9,007,199,254,740,992&lt;/PRE&gt;
&lt;P&gt;So convert it to character. Or split it into two or more numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2019 16:46:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trailing-zeros-in-numeric-variable/m-p/601023#M173803</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-01T16:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Trailing zeros in numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trailing-zeros-in-numeric-variable/m-p/601030#M173808</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226454"&gt;@sfw_09&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am working with a secondary dataset that includes a rather complicated&amp;nbsp;variable where some levels&amp;nbsp;have&amp;nbsp;many trailing zeros.&amp;nbsp;For some reason, not all levels are&amp;nbsp;included when&amp;nbsp;I create a new variable based on the original variable levels. For example, one of the levels for the variable is 1020405100000 (n=16). But when I try to test the creation of a new variable based just on this value using the code below, it does not display the appropriate output of 16. Rather it says "level=0." This pattern continues for levels for this variable that include trailing zeros. However,&amp;nbsp;if I&amp;nbsp;insert&amp;nbsp;shorter levels of the variable&amp;nbsp;such as 1110 (n=20) in the below code, the new variable accurately reflects n=20.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if q12=1020405100000 then newvar=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It was suggested that I attempt to truncate the variable to see this would&amp;nbsp;solve the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;So instead of having:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 1020405100000&lt;/P&gt;
&lt;P&gt;2 10304051000000000&lt;/P&gt;
&lt;P&gt;....;&lt;/P&gt;
&lt;P&gt;It would be:&lt;/P&gt;
&lt;P&gt;1 102040510&lt;/P&gt;
&lt;P&gt;2 103040510&lt;/P&gt;
&lt;P&gt;...;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you think this would solve the issue? If so, how is the best way to truncate the variable and remove the trailing zeros?&lt;/P&gt;
&lt;P&gt;Thank you for any help.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What you show sounds much like string manipulation has been done somewhere along the line. Note that for many purposes a character value will default to 8 characters, which is what you show. And if the value were actually numeric that comparison would yield newvar = 1.&lt;/P&gt;
&lt;P&gt;Proof:&lt;/P&gt;
&lt;PRE&gt;data example;
   q12 = 1020405100000 ;
   if q12=1020405100000 then newvar=1;
run;&lt;/PRE&gt;
&lt;P&gt;So show us the result for proc contents for the variable Q12. I will bet a short stack of $$ that it will show character with length 8.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2019 17:32:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trailing-zeros-in-numeric-variable/m-p/601030#M173808</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-01T17:32:16Z</dc:date>
    </item>
  </channel>
</rss>

