<?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: preserve trailing zero when converting from character to num in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495265#M130673</link>
    <description>&lt;P&gt;Maybe you have some blanks at beginning of FLASH.&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;F&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(STRIP(&lt;/SPAN&gt;FLASH)&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;best32&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 13 Sep 2018 13:02:25 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-09-13T13:02:25Z</dc:date>
    <item>
      <title>preserve trailing zero when converting from character to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495121#M130614</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a column of character like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;flash&lt;/P&gt;&lt;P&gt;1.04&lt;/P&gt;&lt;P&gt;2.11&lt;/P&gt;&lt;P&gt;0.7&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;1.1&lt;/P&gt;&lt;P&gt;2.04&lt;/P&gt;&lt;P&gt;I want them to convert to numeric so I can use mean function.&lt;/P&gt;&lt;P&gt;flash&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.04&lt;/P&gt;&lt;P&gt;2.11&lt;/P&gt;&lt;P&gt;0.70&lt;/P&gt;&lt;P&gt;1.00&lt;/P&gt;&lt;P&gt;1.10&lt;/P&gt;&lt;P&gt;2.04&lt;/P&gt;&lt;P&gt;I tried input(flash, best.), all value are missing... also tried input(flash,best4.2), it becomes&lt;/P&gt;&lt;P&gt;1.04&lt;/P&gt;&lt;P&gt;2.11&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;2.04&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot figure out how to do this...BTW, how can I create another numeric column with the same value? Can anyone provide some detail codes? Thank you so much!&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 01:46:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495121#M130614</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-13T01:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: preserve trailing zero when converting from character to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495127#M130617</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input mydata $;&lt;BR /&gt;cards;&lt;BR /&gt;1.04&lt;BR /&gt;2.11&lt;BR /&gt;0.7&lt;BR /&gt;1&lt;BR /&gt;1.1&lt;BR /&gt;2.04&lt;BR /&gt;;&lt;BR /&gt;data want;&lt;BR /&gt;&amp;nbsp;length mynum 8;&lt;BR /&gt;&amp;nbsp;set have;&lt;BR /&gt;&amp;nbsp;mynum = mydata;&lt;BR /&gt;&amp;nbsp;format mynum 8.2;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 02:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495127#M130617</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-09-13T02:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: preserve trailing zero when converting from character to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495129#M130618</link>
      <description>&lt;P&gt;This works.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  input FLASH $;
cards;
1.04
2.11
0.7
1
1.1
2.04
run;


data WANT;
  set HAVE;
  F=input(FLASH,best.);
  drop FLASH;
  rename F=FLASH;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I suspect your getting missing values means your data is not what you describe.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 101px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23237i4F28CC9A08EFCB1F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 02:11:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495129#M130618</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-13T02:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: preserve trailing zero when converting from character to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495132#M130619</link>
      <description>&lt;P&gt;the length statement creates a new numeric variable&lt;/P&gt;&lt;P&gt;the format statement applies the 8.2 value to the number variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 02:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495132#M130619</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-09-13T02:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: preserve trailing zero when converting from character to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495135#M130620</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122002"&gt;@VDD&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Your code generates the message&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While the informat &lt;FONT face="courier new,courier"&gt;best.&lt;/FONT&gt; is sometimes disappointing, it is best practice to use it (or another format, I usually use&lt;FONT face="courier new,courier"&gt; dollar32.&lt;/FONT&gt;) and to&amp;nbsp;&lt;U&gt;avoid such messages.&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 02:15:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495135#M130620</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-13T02:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: preserve trailing zero when converting from character to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495265#M130673</link>
      <description>&lt;P&gt;Maybe you have some blanks at beginning of FLASH.&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;F&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(STRIP(&lt;/SPAN&gt;FLASH)&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;best32&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Sep 2018 13:02:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495265#M130673</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-09-13T13:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: preserve trailing zero when converting from character to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495279#M130679</link>
      <description>&lt;P&gt;Thank you all! but answers you guys provided are not&amp;nbsp; work for my situation. Flash is a character with 32 length. I also tried&lt;/P&gt;&lt;P&gt;to convert it to num like flash1=flash*1, but only a part of dataset change to num type, others are missing. and I got note as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;/P&gt;&lt;DIV class="sasNote"&gt;75:13&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Invalid numeric data, FLASH='1.04.'&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;why this happen? I feel very confused. Which means this flash column is not the same type of variable at beginning, so that's why some of flash can change to num, while those situation like above can't change. Also, in my output I only see 1.04, why log note display 1.04.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;Any thought will be grateful! Thank you so much for your help!&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 13 Sep 2018 13:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495279#M130679</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-13T13:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: preserve trailing zero when converting from character to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495280#M130680</link>
      <description>Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt; but is doesn't work well for my case</description>
      <pubDate>Thu, 13 Sep 2018 13:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495280#M130680</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-13T13:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: preserve trailing zero when converting from character to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495281#M130681</link>
      <description>Thank you@VDD&lt;BR /&gt;I tried your method, but it failed.</description>
      <pubDate>Thu, 13 Sep 2018 13:40:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495281#M130681</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-13T13:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: preserve trailing zero when converting from character to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495282#M130682</link>
      <description>&lt;P&gt;JoJo,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This looks like you have some unprintable characters in the flash column.&amp;nbsp; Use a text editor that is capable of displaying the hex coding of the data to see if that is the case.&amp;nbsp; If you don't have one, you could also use SAS to print the text field with a HEX format.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 13:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495282#M130682</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2018-09-13T13:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: preserve trailing zero when converting from character to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495292#M130686</link>
      <description>&lt;P&gt;So if your variable is character then you can use the INPUT() function to convert it to a number, But you need to store the number in a new variable, since your existing variable is character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input flash $32. ;
cards;
1.04
2.11
0.7
1
1.1
2.04
;

data want ;
  set have ;
  flash_num = input(flash,32.);
  format flash_num 8.2 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do not use too short of width on your informat.&amp;nbsp; It might be that the values having leading spaces that you don't see when you look at the output.&amp;nbsp; Do not use a decimal part on an informat. That tells SAS to divide any text values that do not have an explicit decimal point by that power of ten.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are still having trouble with the INPUT() function not generating valid numbers then check what is really in your character variable.&amp;nbsp; You could print the values using the $HEX format can check if it contains invisible characters like Carriage Return (0D), Line Feed (0A), Tab (09), Non-Breaking Space (A0), Null (00).&amp;nbsp; If so then remove those.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  flash_num = input(compress(flash,,'kdp'),32.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Sep 2018 14:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495292#M130686</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-09-13T14:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: preserve trailing zero when converting from character to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495314#M130698</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13604"&gt;@Doc_Duke&lt;/a&gt;&amp;nbsp;You remind me about unprintable data. So I search online and I found a article is really useful! I want to share with all of you~&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.lexjansen.com/pharmasug/2010/CC/CC13.pdf" target="_blank"&gt;https://www.lexjansen.com/pharmasug/2010/CC/CC13.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And thank you all! I appreciate your help!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 14:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/preserve-trailing-zero-when-converting-from-character-to-num/m-p/495314#M130698</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-13T14:40:20Z</dc:date>
    </item>
  </channel>
</rss>

