<?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: Converting char to num. input statement yield incorrect results, unsure why? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-char-to-num-input-statement-yield-incorrect-results/m-p/473790#M121614</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45253"&gt;@Tpham&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Roc_1_01a;
set Roc_1_01; 

ROC_01=scan(_id,1," "); 

ROC_01a=ROC_01*1; 
format ROC_01a 8.2; 

ROC_00=input(ROC_01,8.2);

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;So when I just times the character variable by 1, it is correct. I was taught not to do it that way for some reason that I can't remember.&amp;nbsp; &amp;nbsp;I was told to use the input statement, which I have done. However, the input statement didn't yield the correct results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this is my dataset. If you look at the 3rd row, you see the character variable -15. When I use the input statement, it converts it to -0.15 instead of -15. How do I write the code using the input statement to make it appear correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="screen.png" style="width: 412px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21427i443D74A99871FE32/image-dimensions/412x154?v=v2" width="412" height="154" role="button" title="screen.png" alt="screen.png" /&gt;&lt;/span&gt;&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;When you use a format with a stated number of decimals you are telling sas that all of the variables without a decimal in input will be read with implied decimals.&lt;/P&gt;
&lt;P&gt;I suggest for your use to the BEST. informat if your input has mixed numbers of decimal places.&lt;/P&gt;
&lt;P&gt;See&lt;/P&gt;
&lt;PRE&gt;data example;
   string= '1234';
   val1= input(string,best.);
   val2 = input(string,8.0);
   val3 = input(string,8.1);
   val4 = input(string,8.2);
   val5 = input(string,8.3);
   val6 = input(string,8.4);
   
run;&lt;/PRE&gt;
&lt;P&gt;The input function with formats has had this behavior since the days of punch cards. It was very common to define fields on punch cards with "implied decimals" to save character space. So if columns 10 through 20 contained currency values columns 19 and 20 would have the decimal portion but the values would look like 12345678987 and the program was expected to place the decimal before the&amp;nbsp;87 using an 11.2 informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jun 2018 15:39:17 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-06-27T15:39:17Z</dc:date>
    <item>
      <title>Converting char to num. input statement yield incorrect results, unsure why?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-char-to-num-input-statement-yield-incorrect-results/m-p/473570#M121551</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Roc_1_01a;
set Roc_1_01; 

ROC_01=scan(_id,1," "); 

ROC_01a=ROC_01*1; 
format ROC_01a 8.2; 

ROC_00=input(ROC_01,8.2);

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;So when I just times the character variable by 1, it is correct. I was taught not to do it that way for some reason that I can't remember.&amp;nbsp; &amp;nbsp;I was told to use the input statement, which I have done. However, the input statement didn't yield the correct results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this is my dataset. If you look at the 3rd row, you see the character variable -15. When I use the input statement, it converts it to -0.15 instead of -15. How do I write the code using the input statement to make it appear correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="screen.png" style="width: 412px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21427i443D74A99871FE32/image-dimensions/412x154?v=v2" width="412" height="154" role="button" title="screen.png" alt="screen.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 00:17:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-char-to-num-input-statement-yield-incorrect-results/m-p/473570#M121551</guid>
      <dc:creator>Tpham</dc:creator>
      <dc:date>2018-06-27T00:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: Converting char to num. input statement yield incorrect results, unsure why?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-char-to-num-input-statement-yield-incorrect-results/m-p/473790#M121614</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45253"&gt;@Tpham&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Roc_1_01a;
set Roc_1_01; 

ROC_01=scan(_id,1," "); 

ROC_01a=ROC_01*1; 
format ROC_01a 8.2; 

ROC_00=input(ROC_01,8.2);

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;So when I just times the character variable by 1, it is correct. I was taught not to do it that way for some reason that I can't remember.&amp;nbsp; &amp;nbsp;I was told to use the input statement, which I have done. However, the input statement didn't yield the correct results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this is my dataset. If you look at the 3rd row, you see the character variable -15. When I use the input statement, it converts it to -0.15 instead of -15. How do I write the code using the input statement to make it appear correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="screen.png" style="width: 412px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21427i443D74A99871FE32/image-dimensions/412x154?v=v2" width="412" height="154" role="button" title="screen.png" alt="screen.png" /&gt;&lt;/span&gt;&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;When you use a format with a stated number of decimals you are telling sas that all of the variables without a decimal in input will be read with implied decimals.&lt;/P&gt;
&lt;P&gt;I suggest for your use to the BEST. informat if your input has mixed numbers of decimal places.&lt;/P&gt;
&lt;P&gt;See&lt;/P&gt;
&lt;PRE&gt;data example;
   string= '1234';
   val1= input(string,best.);
   val2 = input(string,8.0);
   val3 = input(string,8.1);
   val4 = input(string,8.2);
   val5 = input(string,8.3);
   val6 = input(string,8.4);
   
run;&lt;/PRE&gt;
&lt;P&gt;The input function with formats has had this behavior since the days of punch cards. It was very common to define fields on punch cards with "implied decimals" to save character space. So if columns 10 through 20 contained currency values columns 19 and 20 would have the decimal portion but the values would look like 12345678987 and the program was expected to place the decimal before the&amp;nbsp;87 using an 11.2 informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 15:39:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-char-to-num-input-statement-yield-incorrect-results/m-p/473790#M121614</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-06-27T15:39:17Z</dc:date>
    </item>
  </channel>
</rss>

