<?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: Format confusion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664805#M198668</link>
    <description>&lt;P&gt;Do you know what the the decimal part of an INFORMAT does?&lt;/P&gt;
&lt;P&gt;Example:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA PAY_FILE ;
  LENGTH OUTSTANDING_BAL $ 15 ;
  INPUT  OUTSTANDING_BAL $ ;
CARDS;
000000000120584
00000000005073
0000000008371
000000001000
0000081000
00009000
123.45
;

data test;
  set pay_file;
  value0 = input(outstanding_bal,15.);
  value1 = input(outstanding_bal,15.1);
  value2 = input(outstanding_bal,15.2);
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    OUTSTANDING_BAL       value0     value1      value2

 1     000000000120584    120584.00    12058.40    1205.84
 2     00000000005073       5073.00      507.30      50.73
 3     0000000008371        8371.00      837.10      83.71
 4     000000001000         1000.00      100.00      10.00
 5     0000081000          81000.00     8100.00     810.00
 6     00009000             9000.00      900.00      90.00
 7     123.45                123.45      123.45     123.45&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jun 2020 23:10:16 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-06-24T23:10:16Z</dc:date>
    <item>
      <title>Format confusion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664802#M198666</link>
      <description>&lt;P&gt;Please help me understand why the column ending in "BAD" formats the input ending with 00 like that. I would have expected the same results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;DATA PAY_FILE ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; LENGTH OUTSTANDING_BAL $ 15 ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FORMAT OUTSTANDING_BAL $CHAR15. ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INPUT&amp;nbsp; OUTSTANDING_BAL $ ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CARDS;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 000000000120584&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 000000000005073&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 000000000008371&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 000000000001000&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 000000000081000&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 000000000009000&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;DATA PAY_FILE;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;SET PAY_FILE;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;FORMAT OUTSTANDING_BAL_OK1 dollar20.2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;OUTSTANDING_BAL_OK1 = INPUT(STRIP(INPUT(CAT(SUBSTR(OUTSTANDING_BAL,1,LENGTH(OUTSTANDING_BAL)-2),".",SUBSTR(OUTSTANDING_BAL,LENGTH(OUTSTANDING_BAL)-1,2)),20.)),10.);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;OUTSTANDING_BAL_OK2 = INPUT(STRIP(INPUT(CAT(SUBSTR(OUTSTANDING_BAL,1,LENGTH(OUTSTANDING_BAL)-2),".",SUBSTR(OUTSTANDING_BAL,LENGTH(OUTSTANDING_BAL)-1,2)),20.)),10.);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;OUTSTANDING_BAL_BAD = INPUT(STRIP(INPUT(CAT(SUBSTR(OUTSTANDING_BAL,1,LENGTH(OUTSTANDING_BAL)-2),".",SUBSTR(OUTSTANDING_BAL,LENGTH(OUTSTANDING_BAL)-1,2)),20.)),DOLLAR20.2);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;RUN;&lt;/FONT&gt;&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="cgarciam80_0-1593038886530.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/46611iBBCE5C1F75AFFC2F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cgarciam80_0-1593038886530.png" alt="cgarciam80_0-1593038886530.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 22:49:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664802#M198666</guid>
      <dc:creator>cgarciam80</dc:creator>
      <dc:date>2020-06-24T22:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Format confusion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664804#M198667</link>
      <description>&lt;P&gt;Can you explain what you are trying to do?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 22:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664804#M198667</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-24T22:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: Format confusion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664805#M198668</link>
      <description>&lt;P&gt;Do you know what the the decimal part of an INFORMAT does?&lt;/P&gt;
&lt;P&gt;Example:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA PAY_FILE ;
  LENGTH OUTSTANDING_BAL $ 15 ;
  INPUT  OUTSTANDING_BAL $ ;
CARDS;
000000000120584
00000000005073
0000000008371
000000001000
0000081000
00009000
123.45
;

data test;
  set pay_file;
  value0 = input(outstanding_bal,15.);
  value1 = input(outstanding_bal,15.1);
  value2 = input(outstanding_bal,15.2);
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    OUTSTANDING_BAL       value0     value1      value2

 1     000000000120584    120584.00    12058.40    1205.84
 2     00000000005073       5073.00      507.30      50.73
 3     0000000008371        8371.00      837.10      83.71
 4     000000001000         1000.00      100.00      10.00
 5     0000081000          81000.00     8100.00     810.00
 6     00009000             9000.00      900.00      90.00
 7     123.45                123.45      123.45     123.45&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 23:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664805#M198668</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-24T23:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: Format confusion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664806#M198669</link>
      <description>&lt;P&gt;The input is a character field with length 15. (It comes from an external source but I created it here in order to ask my question).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal was to add a decimal point before the last to digits of the character field and made that dollar amount. It worked for most of the fields but those ending in "00" did not work. I realized I could have done it differently but I am still curious about why it did not work.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 23:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664806#M198669</guid>
      <dc:creator>cgarciam80</dc:creator>
      <dc:date>2020-06-24T23:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Format confusion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664807#M198670</link>
      <description>&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: inherit; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 1.7142; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;My goal was to add a decimal point before the last to digits of the character field and made that a dollar amount. It worked for most of the values but those ending in "00" did not work. I realize I could have done it differently but I am still curious about why it did not work.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 23:14:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664807#M198670</guid>
      <dc:creator>cgarciam80</dc:creator>
      <dc:date>2020-06-24T23:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: Format confusion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664813#M198673</link>
      <description>&lt;P&gt;You could either read the variable&amp;nbsp;&lt;SPAN&gt;OUTSTANDING_BAL using &lt;STRONG&gt;informat&lt;/STRONG&gt; 15.2 instead $&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA PAY_FILE ;
    /* LENGTH OUTSTANDING_BAL $ 15 ; */
    FORMAT OUTSTANDING_BAL 15.2 ;
     INPUT  OUTSTANDING_BAL 15.2;
     CARDS;
     000000000120584
     000000000005073
     000000000008371
     000000000001000
     000000000081000
     000000000009000
     ;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;or you can repair it by:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data pay_file;
   OUTSTANDING_BAL_OK = input(OUTSTANDING_BAL, 15.2);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jun 2020 00:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664813#M198673</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-06-25T00:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: Format confusion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664814#M198674</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138913"&gt;@cgarciam80&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: inherit; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 1.7142; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;My goal was to add a decimal point before the last to digits of the character field and made that a dollar amount. It worked for most of the values but those ending in "00" did not work. I realize I could have done it differently but I am still curious about why it did not work.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's deconstruct your nested function calls:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;len=LENGTH(OUTSTANDING_BAL);
str1=SUBSTR(OUTSTANDING_BAL,1,len-2);
str2=SUBSTR(OUTSTANDING_BAL,len-1,2);
str3=CAT(str1,".",str2);
num1=INPUT(str3,20.);
str4=STRIP(num1);
OUTSTANDING_BAL_BAD = INPUT(str4,DOLLAR20.2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;EM&gt;Note that this might add spaces into STR3 depending on how long STR1 and STR2 get defined. Change CAT() to CATS() to prevent that.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your big mistake is added those last two steps. NUM1 is the number you want.&amp;nbsp; By first converting it to a string and back to a number again you have introduced a point where there can be changes.&amp;nbsp; First the default conversion SAS will do when convert NUM1 into a character string so that the STRIP() function can operate on it is that it will use BEST12 to format the number.&amp;nbsp; So if the value needs more than 12 characters you will loose precision.&amp;nbsp; But second for integer values it will NOT insert an explicit decimal point into the string, so the implied decimal point of the DOLLAR20.2 informat will end up dividing any whole numbers by 100.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you just trying to create another text string? Or create a numeric variable?&amp;nbsp; If you want to create a string use the STR3 value with period inserted before the last two characters.&amp;nbsp; If you want to create a numeric variable then use the INPUT() function with the 20.2 informat.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OUTSTANDING_BAL_BAD = INPUT(OUTSTANDING_BAL,20.2)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That .2 means that SAS should assume the decimal point is before the last two characters, when there is not one in the string being read.&amp;nbsp; That is it divides such values but 10**2.&lt;/P&gt;
&lt;P&gt;If the string&amp;nbsp;OUTSTANDING_BAL can contain commas and dollar signs you could use COMMA20.2 informat instead.&amp;nbsp; Note that the DOLLAR informat is just an alias for the COMMA informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 00:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664814#M198674</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-25T00:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Format confusion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664905#M198702</link>
      <description>&lt;P&gt;Both of your codes are an example for overcomplicating things, and how that ends with shooting oneself in the foot. The following leads to the exact same result, with a minimum of effort:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data PAY_FILE;
input OUTSTANDING_BAL $15.;
cards;
000000000120584
000000000005073
000000000008371
000000000001000
000000000081000
000000000009000
;

data PAY_FILE_want;
set PAY_FILE;
format OUTSTANDING_BAL_num dollar20.2;
OUTSTANDING_BAL_num = input(OUTSTANDING_BAL,15.2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See the first quote of Maxim 37.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 08:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-confusion/m-p/664905#M198702</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-25T08:30:21Z</dc:date>
    </item>
  </channel>
</rss>

