<?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: Reading decimals from xlsx/xls in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315442#M68808</link>
    <description>&lt;P&gt;You will have to change the format on the columns and test if that makes a difference in the file(s). Save the Excel file to a new name to preserve the original one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be also aware that you might lose some precision on the import, as SAS can only store around 15 decimal digits in the mantissa of its 8-byte real format.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Nov 2016 09:12:56 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-11-30T09:12:56Z</dc:date>
    <item>
      <title>Reading decimals from xlsx/xls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315422#M68795</link>
      <description>&lt;P&gt;I have a xlsx file with variables having decimals upto 15. when I open the xls file only 4-7 decimals are visible(actual data in formula bar has 15 decimals but only 4 decimals are visible on the cell)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now when I import the data in SAS only those visisble decimals are populating is SAS(only 4-7 decimals not 15), even when I use informats like 20.15 or best20.15 and formats like $100&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: The excel file is not allowed to change&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 06:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315422#M68795</guid>
      <dc:creator>bhos123</dc:creator>
      <dc:date>2016-11-30T06:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Reading decimals from xlsx/xls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315432#M68800</link>
      <description>&lt;P&gt;Export the data from Excel to a csv file and inspect that with a text editor, to see what Excel actually exports.&lt;/P&gt;
&lt;P&gt;Note: The Excel file format is not suited for data transfer.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 08:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315432#M68800</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-30T08:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Reading decimals from xlsx/xls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315441#M68807</link>
      <description>&lt;P&gt;Thanks Kurt, The csv file itself showing 4 decimals, that means when I convert excel to csv, only the visible decimals are coming in csv(not all the 15 decimals)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I solve this problem without changing the excel file?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 09:04:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315441#M68807</guid>
      <dc:creator>bhos123</dc:creator>
      <dc:date>2016-11-30T09:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: Reading decimals from xlsx/xls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315442#M68808</link>
      <description>&lt;P&gt;You will have to change the format on the columns and test if that makes a difference in the file(s). Save the Excel file to a new name to preserve the original one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be also aware that you might lose some precision on the import, as SAS can only store around 15 decimal digits in the mantissa of its 8-byte real format.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 09:12:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315442#M68808</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-30T09:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: Reading decimals from xlsx/xls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315443#M68809</link>
      <description>&lt;P&gt;I tried this and it worked perfectly. The only problem is I am not allowed to increase the number of decimals in excel. That means I am not allowed to do any changes to excel file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way I can achieve this without making any changes to my excel file?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 09:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315443#M68809</guid>
      <dc:creator>bhos123</dc:creator>
      <dc:date>2016-11-30T09:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reading decimals from xlsx/xls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315445#M68810</link>
      <description>&lt;P&gt;I have found your problem:&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;Note: The excel file is not allowed to change"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Its the part wher you say something is not able to change, even if it may be wrong. &amp;nbsp;Excel is a really poor data format for any purpose, you will come across many examples of this, hiding things, displaying data incorrectly and other features. &amp;nbsp;First you will need to fix the export of that data into a file which contains all the data. &amp;nbsp;If SaveAs-&amp;gt; CSV produces a file with only the displayed value of four digits (which is unusual), then you might need to export it yourself from VBA. &amp;nbsp;Open VBA editor (alt+f11 usually), and write some code which loops over each cell and prints out to a plain file the correct value - this may be the value property or it might be the formula property or one of the others. &amp;nbsp;Here shows how to print to file, modify it to use formatted values, or .format value depedning on what you need out.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="http://stackoverflow.com/questions/15125578/vba-print-1-select-range-for-exporting-from-excel-to-a-file" target="_blank"&gt;http://stackoverflow.com/questions/15125578/vba-print-1-select-range-for-exporting-from-excel-to-a-file&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Note that you don't need to save the file to do this, nor does VBA have to reside in the same file as the data. &amp;nbsp;However fixing something that is broken should be your number 1 priority.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 09:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315445#M68810</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-30T09:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: Reading decimals from xlsx/xls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315449#M68813</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117440"&gt;@bhos123&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I tried this and it worked perfectly. The only problem is I am not allowed to increase the number of decimals in excel. That means I am not allowed to do any changes to excel file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way I can achieve this without making any changes to my excel file?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well, you can make the changes in the spreadsheet, export to csv, and then not save back to the original format.&lt;/P&gt;
&lt;P&gt;You WILL have to change the display formats before exporting, as SAS needs the formatted values to determine column attributes. Period.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is all because Excel (and other spreadsheet programs) does not have the structure of a database, where attributes are fixed for a column throughout, and values and formats are two different and separate things. In Excel, each cell can have its own attributes. Since there is no column attribute (like "this is a date column") that would enable the separate transfer of raw values, you have to make the format changes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 09:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315449#M68813</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-30T09:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Reading decimals from xlsx/xls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315456#M68818</link>
      <description>&lt;P&gt;Not working, I have attached the files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Book1.xlsx - original file&lt;/P&gt;&lt;P&gt;Book1.csv - csv converted file(open with notepad or Import in SAS you will see only few decimals)&lt;/P&gt;&lt;P&gt;Book2.csv - csv converted using VBA code given below( same problem as above)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sub vba_code_to_convert_excel_to_csv()&lt;BR /&gt;Set wb = Workbooks.Open("C:\Users\1307608\Desktop\Book1.xlsx")&lt;BR /&gt;wb.SaveAs Filename:="C:\Users\1307608\Desktop\Book2.csv", FileFormat:=xlCSV, CreateBackup:=False&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 09:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315456#M68818</guid>
      <dc:creator>bhos123</dc:creator>
      <dc:date>2016-11-30T09:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: Reading decimals from xlsx/xls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315459#M68819</link>
      <description>&lt;P&gt;Sorry, please re-read my post and look at the link provided. &amp;nbsp;Step 1 and 2 you have done is exactly the same thing, you have just called the SaveAS CSV command form VBA which is not what I posted. &amp;nbsp;The SaveAS CSV function streams the "values" as they are displayed to the CSV file which is where your problem lies. &amp;nbsp;What you need is the VBA code in the link I sent you, but instead of outputting c.Value, you would need to output the particular proprty of each cell which contains the full value - it may be c.Formula. &amp;nbsp;I can't tell offhand which property it is (and I am afraid I wouldn't download any Office files form the net), so just fiddle around with the different properties.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 10:21:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315459#M68819</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-30T10:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: Reading decimals from xlsx/xls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315460#M68820</link>
      <description>&lt;P&gt;Just saving as csv from VBA will have the same effect as if you had done it manually, namely none.&lt;/P&gt;
&lt;P&gt;Before saving as csv, you need to change the cell formats.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 10:25:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315460#M68820</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-30T10:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Reading decimals from xlsx/xls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315523#M68847</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;This shoud work regardless of the format(appearance) of the number in excel.&lt;BR /&gt;&lt;BR /&gt;You will need to change to numeric in SAS, which you can do in the outer SQL using&lt;BR /&gt;input(ChrNum,best15.) as ChrNum&lt;BR /&gt;&lt;BR /&gt;/* T0100580 Casting 15 digit excel numbers to character using passthru
Casting 15 digit excel numbers to character using passthru

inspired by
https://goo.gl/jnnQqa
https://communities.sas.com/t5/Base-SAS-Programming/Excel-import-Exponential-value-into-SAS-as-character-field/m-p/312116

HAVE ( Where X is numeric)

  +------------------+
  |        A         |
--+------------------+
1 | X                |
--|------------------+
2 |  1202220022121120|
---------------------+
3 |  1202220022121120|
---------------------+
4 |  1202220022121120|
--+------------------+

num18

WANT
====

WANT  (note the sheet name is num18 could be the default)
====

Up to 40 obs WORK.XLS_CAST total obs=3

Obs         CHRNUM

 1     1202220022121120
 2     1202220022121120
 3     1202220022121120

WORKING CODE

 format(X,'################') as ChrNum


FULL SOLUTION
=============

* create a sheet with the 15 digit numbers;

%utlfkil(d:/xls/utl_excel_cast.xlsx);
libname xel "d:/xls/utl_excel_cast.xlsx";
data xel.num18;
  do x=1202220022121121,1202220022121121,1202220022121121;
     output;
  end;
run;quit;
libname xel clear;

* cast the numbers to char using passthru;
proc sql dquote=ansi;
  connect to excel (Path="d:\xls\utl_excel_cast.xlsx" mixed=yes);
    create table xls_cast as
    select
        ChrNum     length=16
        from connection to Excel
        (
         Select
            format(X,'################') as ChrNum
         from
           num18
        );
    disconnect from Excel;
Quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Nov 2016 14:01:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315523#M68847</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2016-11-30T14:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: Reading decimals from xlsx/xls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315820#M68933</link>
      <description>Thanks RW9. This c.value worked for me perfectly.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Dec 2016 05:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-decimals-from-xlsx-xls/m-p/315820#M68933</guid>
      <dc:creator>bhos123</dc:creator>
      <dc:date>2016-12-01T05:08:45Z</dc:date>
    </item>
  </channel>
</rss>

