<?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: Problem with format when loading from CSV file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-format-when-loading-from-CSV-file/m-p/470962#M285589</link>
    <description>Add a format for your variable. &lt;BR /&gt;format VAR comma20.2;&lt;BR /&gt;</description>
    <pubDate>Mon, 18 Jun 2018 03:36:46 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2018-06-18T03:36:46Z</dc:date>
    <item>
      <title>Problem with format when loading from CSV file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-format-when-loading-from-CSV-file/m-p/469826#M285585</link>
      <description>&lt;P&gt;Good day everyone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to load a csv file by using SAS Data Integration Studio with File Reader.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the thing. The raw data looks something like this:&lt;/P&gt;&lt;PRE&gt;4048,3.18,USD,3.18,18-Dec-2008,3
4048,102,CAD,102,12-Jan-2009,102&lt;/PRE&gt;&lt;P&gt;The columns are:&lt;/P&gt;&lt;P&gt;StaffID Character 4&lt;/P&gt;&lt;P&gt;BankAmt Numeric Informat-Comma10.2&lt;/P&gt;&lt;P&gt;Currency Character 3&lt;/P&gt;&lt;P&gt;WalletAmt Numeric Informat-Comma10.2&lt;/P&gt;&lt;P&gt;Date DATE9.&lt;/P&gt;&lt;P&gt;Tips Numeric Informat-Comma10.2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when i load it using the above Informat, Tips for the first record became 0.03 instead of 3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know why?&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>Wed, 13 Jun 2018 04:03:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-format-when-loading-from-CSV-file/m-p/469826#M285585</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-06-13T04:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with format when loading from CSV file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-format-when-loading-from-CSV-file/m-p/469830#M285586</link>
      <description>&lt;P&gt;Because that is what you told it to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you specify a decimal part on an INFORMAT you are telling SAS where to place an implied decimal point when the text being read does not include a decimal point. So by use 10.2 as in the informat a value with only one digit, like &lt;STRONG&gt;3&lt;/STRONG&gt; is taken to mean &lt;STRONG&gt;0.03.&amp;nbsp; &lt;/STRONG&gt;And a value with three digits without an period, like &lt;STRONG&gt;102&lt;/STRONG&gt; means&amp;nbsp;&lt;STRONG&gt;1.02&lt;/STRONG&gt;.&amp;nbsp; When the value already has a period then one is not implied, so a value like &lt;STRONG&gt;12.34&lt;/STRONG&gt; is read as &lt;STRONG&gt;12.34&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use an INFORMAT of 10.&amp;nbsp; or better still leave it blank if the tool will let you.&amp;nbsp; SAS already knows how to read numbers from text files so you don't need to override its default behavior by telling it to use some special instructions.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 04:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-format-when-loading-from-CSV-file/m-p/469830#M285586</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-06-13T04:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with format when loading from CSV file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-format-when-loading-from-CSV-file/m-p/469832#M285587</link>
      <description>&lt;P&gt;SAS expects two decimals.&lt;/P&gt;
&lt;P&gt;This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file "%sysfunc(pathname(WORK))\t.txt";
  put '4048,3.18,USD,3.18,18-Dec-2008,3';
  put '4048,102,CAD,102,12-Jan-2009,102';
run;

data WANT;
  infile "%sysfunc(pathname(WORK))\t.txt" dlm=',';
  informat STAFFID   $4.
           BANKAMT   comma20.
           CURRENCY  $3.
           WALLETAMT comma20.
           DATE      date9.
           TIPS      comma20.;
  input STAFFID            
        BANKAMT 
        CURRENCY 
        WALLETAMT 
        DATE 
        TIPS   ; 
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;STAFFID&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;BANKAMT&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;CURRENCY&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;WALLETAMT&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;DATE&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;TIPS&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;4048&lt;/TD&gt;
&lt;TD class="r data"&gt;3.18&lt;/TD&gt;
&lt;TD class="l data"&gt;USD&lt;/TD&gt;
&lt;TD class="r data"&gt;3.18&lt;/TD&gt;
&lt;TD class="r data"&gt;17884&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;4048&lt;/TD&gt;
&lt;TD class="r data"&gt;102.00&lt;/TD&gt;
&lt;TD class="l data"&gt;CAD&lt;/TD&gt;
&lt;TD class="r data"&gt;102.00&lt;/TD&gt;
&lt;TD class="r data"&gt;17909&lt;/TD&gt;
&lt;TD class="r data"&gt;102&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 13 Jun 2018 04:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-format-when-loading-from-CSV-file/m-p/469832#M285587</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-06-13T04:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with format when loading from CSV file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-format-when-loading-from-CSV-file/m-p/470961#M285588</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I changed the number formatting to remove comma in CSV file.&lt;/P&gt;&lt;P&gt;When I load it into SAS Dataset, there is no more comma for 1000 onwards.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HOWEVER, if i add comma back to 1000 in CSV, SAS will never be able to read it if i don't put COMMA10.2.&lt;/P&gt;&lt;P&gt;By using COMMA10., SAS ignores all my decimal value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help if my CSV number doesnt have comma, how do i add comma back?&lt;/P&gt;&lt;P&gt;What if my CSV number contains comma, how do i make sure SAS read it properly.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 03:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-format-when-loading-from-CSV-file/m-p/470961#M285588</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-06-18T03:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with format when loading from CSV file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-format-when-loading-from-CSV-file/m-p/470962#M285589</link>
      <description>Add a format for your variable. &lt;BR /&gt;format VAR comma20.2;&lt;BR /&gt;</description>
      <pubDate>Mon, 18 Jun 2018 03:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-format-when-loading-from-CSV-file/m-p/470962#M285589</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-06-18T03:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with format when loading from CSV file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-format-when-loading-from-CSV-file/m-p/470964#M285590</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/63520"&gt;@imdickson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I changed the number formatting to remove comma in CSV file.&lt;/P&gt;
&lt;P&gt;When I load it into SAS Dataset, there is no more comma for 1000 onwards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HOWEVER, if i add comma back to 1000 in CSV, SAS will never be able to read it if i don't put COMMA10.2.&lt;/P&gt;
&lt;P&gt;By using COMMA10., SAS ignores all my decimal value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need help if my CSV number doesnt have comma, how do i add comma back?&lt;/P&gt;
&lt;P&gt;What if my CSV number contains comma, how do i make sure SAS read it properly.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You seem confused about the difference between an INFORMAT and a FORMAT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A FORMAT is instructions for how to convert values into text. So how you want the values to print. An INFORMAT is instructions for how to convert text into values. So how you want interpret values read from a text file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the value to display with commas you need to use COMMA format.&amp;nbsp; If you want it to display digits to the right of the decimal place then include the number of digits you want in the format specifications.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But do NOT include a number of decimal places when using an INFORMAT, unless you purposely multiplied the value by that power of ten before writing it to the text file so that you did not need to write the period into the text file.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 04:09:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-format-when-loading-from-CSV-file/m-p/470964#M285590</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-06-18T04:09:35Z</dc:date>
    </item>
  </channel>
</rss>

