<?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: SAS rounds Excel cell values on import in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-rounds-Excel-cell-values-on-import/m-p/854492#M337701</link>
    <description>&lt;P&gt;SAS will assign a display FORMAT, typically a BEST of some flavor. That FORMAT may be doing rounding to fit that definition.&lt;/P&gt;
&lt;P&gt;You can change the format to show more digits. Try a BEST16. with values in the range you are showing.&lt;/P&gt;
&lt;P&gt;Also, when you deal with very small decimal values you can run into storage precision of how many digits can be stored in 8 bytes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can run this code and see some examples of displaying a value with different formats.&lt;/P&gt;
&lt;PRE&gt;data example;
   file print;
   x = 0.0012345678;
   put x= best4.;
   put x= best6.;
   put x= best8.;
   put x= best10.;
   put x= best12.;
   put x= 16.14;
run;&lt;/PRE&gt;
&lt;P&gt;The bit after the X= is the format assignment for how to display the value of X by that Put statement.&lt;/P&gt;</description>
    <pubDate>Thu, 19 Jan 2023 05:16:27 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-01-19T05:16:27Z</dc:date>
    <item>
      <title>SAS rounds Excel cell values on import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-rounds-Excel-cell-values-on-import/m-p/854487#M337700</link>
      <description>&lt;P&gt;I am using a step that imports values from Excel:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC IMPORT OUT = SV_VAR_VALUES
    DATAFILE = "&amp;amp;SV_PATH" DBMS = EXCEL REPLACE;
    RANGE = "&amp;amp;SV_VALUE_RANGE"; 
    GETNAMES = NO;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Some values are very small numbers (e.g.,0.000124688 and&amp;nbsp;0.007665256) which SAS rounds to 0.0001 and 0.0077.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Its not just displaying these with 4 decimal places, it is storing and using them at the 4-decimal place level.&amp;nbsp; I know this because, if I instead multiply these by 1000 in the Excel file, and after importation, divide them by 1000, I do get the correct value.&amp;nbsp; I also know this because when these imported values are multiplied by another value and, the result is different (and it is accurate with the *1000+ /1000 method).&amp;nbsp; For example, if I have SAS multiply that imported value by 393, I get .0393 using the straight up method, but I get 0.0490 using the *1000+ /1000 method.&amp;nbsp; I get different values still, if I multiply/divide by 10,000 or 100,000.&amp;nbsp; SAS is definitely truncating the imported value to 4 decimal places.&amp;nbsp; The Excel values are not hard-coded, but are cells with formulas if that matters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone explain why this happens and how to avoid the temporary workaround?&amp;nbsp; Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 05:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-rounds-Excel-cell-values-on-import/m-p/854487#M337700</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2023-01-19T05:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS rounds Excel cell values on import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-rounds-Excel-cell-values-on-import/m-p/854492#M337701</link>
      <description>&lt;P&gt;SAS will assign a display FORMAT, typically a BEST of some flavor. That FORMAT may be doing rounding to fit that definition.&lt;/P&gt;
&lt;P&gt;You can change the format to show more digits. Try a BEST16. with values in the range you are showing.&lt;/P&gt;
&lt;P&gt;Also, when you deal with very small decimal values you can run into storage precision of how many digits can be stored in 8 bytes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can run this code and see some examples of displaying a value with different formats.&lt;/P&gt;
&lt;PRE&gt;data example;
   file print;
   x = 0.0012345678;
   put x= best4.;
   put x= best6.;
   put x= best8.;
   put x= best10.;
   put x= best12.;
   put x= 16.14;
run;&lt;/PRE&gt;
&lt;P&gt;The bit after the X= is the format assignment for how to display the value of X by that Put statement.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 05:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-rounds-Excel-cell-values-on-import/m-p/854492#M337701</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-19T05:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: SAS rounds Excel cell values on import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-rounds-Excel-cell-values-on-import/m-p/854495#M337702</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/296215"&gt;@texasmfp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am using a step that imports values from Excel:&lt;/P&gt;
&lt;P&gt;[...]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone explain why this happens and how to avoid the temporary workaround?&amp;nbsp; Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Workaround: Don't use excel as data source, use csv instead and write a data step to read the file. Or: have you tried using dbms=xlsx instead?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 05:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-rounds-Excel-cell-values-on-import/m-p/854495#M337702</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-01-19T05:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: SAS rounds Excel cell values on import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-rounds-Excel-cell-values-on-import/m-p/854498#M337705</link>
      <description>&lt;P&gt;It turns out, the issue was how the values were formatted in Excel.&amp;nbsp; The number was formatted as a dollar value; which SAS truncated to 4 decimals.&amp;nbsp; When I switch it to straight number formatting in Excel, SAS imported it to 10 decimal places and carried that extended value through the calculations.&amp;nbsp; Thanks Andreas_lds and ballardw for getting me thinking.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 06:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-rounds-Excel-cell-values-on-import/m-p/854498#M337705</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2023-01-19T06:36:28Z</dc:date>
    </item>
  </channel>
</rss>

