<?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 data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722881#M224224</link>
    <description>Thank you--Your suggested code now reads my data as 0.07. I checked my excel file and the 20 decimals were all 0 after 7.&lt;BR /&gt;I was receiving a note about "invalid arguments" and I added "??" before 32. and it solved the issue.&lt;BR /&gt;varnum=input(left(var​char), ?? 32.);&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
    <pubDate>Tue, 02 Mar 2021 15:35:58 GMT</pubDate>
    <dc:creator>Emma_at_SAS</dc:creator>
    <dc:date>2021-03-02T15:35:58Z</dc:date>
    <item>
      <title>reading data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722692#M224121</link>
      <description>&lt;DIV&gt;I read a .xlsx data in SAS using proc import:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;options validvarname=v7;&amp;nbsp;
&lt;DIV&gt;proc import datafile="&amp;amp;proj_loc\my_data.xlsx"&lt;/DIV&gt;
&lt;DIV&gt;dbms=xlsx&lt;/DIV&gt;
&lt;DIV&gt;replace&lt;/DIV&gt;
&lt;DIV&gt;out=SAS_data;&lt;/DIV&gt;
run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;One of my numeric&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;columns&amp;nbsp;&lt;/SPAN&gt;with 2 decimal places in the Excel file is read as a character variable in SAS.&lt;/DIV&gt;
&lt;DIV&gt;I switched that to numeric using var&lt;I&gt;num=input(var&lt;/I&gt;​char, best14.);&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;The problem is some values are read with exponential format during the proc import and the best14. does not fix them.&lt;/DIV&gt;
&lt;DIV&gt;For example, a 0.07 is imported as&amp;nbsp;7.0000000000000007E-2 and in the var_num it is read as only 7.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I appreciate it if you have any suggestions to fix this.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Thanks&lt;/DIV&gt;</description>
      <pubDate>Mon, 01 Mar 2021 20:55:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722692#M224121</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-03-01T20:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: reading data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722702#M224126</link>
      <description>If a variable is in exponential format, check the variable type/format. If it's a numeric type you just need to change the format. If it's a character variable, you need to provide the correct type to the INPUT function. &lt;BR /&gt;&lt;BR /&gt;format variableName 12.2;&lt;BR /&gt;&lt;BR /&gt;That should show the value with 2 decimal places, if possible.</description>
      <pubDate>Mon, 01 Mar 2021 21:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722702#M224126</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-01T21:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: reading data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722732#M224148</link>
      <description>&lt;P&gt;How do you know the starting value is 0.07 and not 0.070000000000002 or similar in Excel? Most default numeric cells in Excel will use 2 decimals for display unless you force otherwise.&lt;/P&gt;
&lt;P&gt;If the value is "read as character" then you would not see any exponential informat or format or exponential appearing value. You would see something like $14. as the informat/format in the variable characteristics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having a hard time seeing how "I switched that to numeric using var&lt;I&gt;num=input(var&lt;/I&gt;​char, best14.);" has anything to do with Proc import and an exponential value. If the value was "read with an exponential format (sic)" in the first place the variable is numeric and using Input(&amp;lt;anything here referencing that imported value&amp;gt;,best14) would have an IMPLICIT conversion from the numeric value to character to use the Input function. And that implicit conversion is likely the wrong format. Did your code show any messages like:&lt;/P&gt;
&lt;PRE&gt;NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
&lt;/PRE&gt;
&lt;P&gt;then the existing format would have been used to convert the numeric value to character prior to use of input. Which is very likely to have an incorrect result since most import steps will end up with a BEST12 format. So the result would be truncated to 12 characters before the input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Mar 2021 22:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722732#M224148</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-01T22:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: reading data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722754#M224154</link>
      <description>&lt;P&gt;If the column in the Excel file has mixed character and numeric cells then the variable will be character.&lt;/P&gt;
&lt;P&gt;If you want to convert a string to a number just use the normal informat.&amp;nbsp; The maximum width that the numeric informat can handle is 32 bytes.&amp;nbsp; The INPUT() function does not care if the width used in the informat is wider than the length of the string being read.&amp;nbsp; But leading spaces might have an inpact.&amp;nbsp; The width used for the informat in your code (14) is shorter than the length of the example text (21) in your question so you did not read the E-02 part.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;varnum=input(left(var​char), 32.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that BEST as an INformat is just treated as an alias for the normal numeric informat.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 01:10:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722754#M224154</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-02T01:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: reading data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722881#M224224</link>
      <description>Thank you--Your suggested code now reads my data as 0.07. I checked my excel file and the 20 decimals were all 0 after 7.&lt;BR /&gt;I was receiving a note about "invalid arguments" and I added "??" before 32. and it solved the issue.&lt;BR /&gt;varnum=input(left(var​char), ?? 32.);&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Tue, 02 Mar 2021 15:35:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722881#M224224</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-03-02T15:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: reading data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722883#M224225</link>
      <description>Thank you! I checked and my number is really 0.07</description>
      <pubDate>Tue, 02 Mar 2021 15:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722883#M224225</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-03-02T15:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: reading data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722913#M224243</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84351"&gt;@Emma_at_SAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you--Your suggested code now reads my data as 0.07. I checked my excel file and the 20 decimals were all 0 after 7.&lt;BR /&gt;I was receiving a note about "invalid arguments" and I added "??" before 32. and it solved the issue.&lt;BR /&gt;varnum=input(left(var​char), ?? 32.);&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This will suppress any warnings. So if you have values that are wrong for any reason, for example someone typed in "eight" instead of 8, you won't notice that they're missing. Is that what you want to happen?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 17:00:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722913#M224243</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-02T17:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: reading data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722917#M224246</link>
      <description>&lt;P&gt;Thank you, Reeza, for mentioning that. No, that was not what I wanted to do! I will go back and check the warnings!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 17:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722917#M224246</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-03-02T17:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: reading data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722943#M224260</link>
      <description>&lt;P&gt;My SAS code is&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;var1_num=input(left(var1),32.);&lt;BR /&gt;var2_num=input(left(var2), 32.);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The NOTE in the SAS log says:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Invalid argument to function INPUT at line 1007 column 9.&lt;BR /&gt;NOTE: Invalid argument to function INPUT at line 1008 column 10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run the input lines separately the line and column in the NOTE changes. I cannot match these lines and columns to my data. Is this something I have to check? Other thoughts?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 18:38:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722943#M224260</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-03-02T18:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: reading data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722956#M224266</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84351"&gt;@Emma_at_SAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My SAS code is&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;var1_num=input(left(var1),32.);&lt;BR /&gt;var2_num=input(left(var2), 32.);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The NOTE in the SAS log says:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Invalid argument to function INPUT at line 1007 column 9.&lt;BR /&gt;NOTE: Invalid argument to function INPUT at line 1008 column 10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run the input lines separately the line and column in the NOTE changes. I cannot match these lines and columns to my data. Is this something I have to check? Other thoughts?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please look at your SAS log more carefully.&amp;nbsp; SAS will show you in detail what the offending data.&amp;nbsp; For example try this program.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  input var1 $ var2 $ ;
  var1_num=input(left(var1),32.);
  var2_num=input(left(var2), 32.);
cards;
12.3 4.5 
. .
abc def 
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Resulting LOG&lt;/P&gt;
&lt;PRE&gt;1735  data want;
1736    input var1 $ var2 $ ;
1737    var1_num=input(left(var1),32.);
1738    var2_num=input(left(var2), 32.);
1739  cards;

NOTE: Invalid argument to function INPUT at line 1737 column 12.
NOTE: Invalid argument to function INPUT at line 1738 column 12.
RULE:       ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+
1742        abc def
var1=abc var2=def var1_num=. var2_num=. _ERROR_=1 _N_=3
NOTE: Mathematical operations could not be performed at the following places. The results of the
      operations have been set to missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 1737:12   1 at 1738:12
NOTE: The data set WORK.WANT has 3 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;Notice how it actually lists the value of VAR1 and VAR2 that caused the error.&amp;nbsp; And since my example is reading the data from text instead of using a SET statement it also lists the actual line of text read for that observation that generated the errors.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 19:40:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722956#M224266</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-02T19:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: reading data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722996#M224280</link>
      <description>Thank you very much, Tom. Your post was very helpful! &lt;BR /&gt;In my Excel data, I have NA for the missing observations. Because of these character observations, SAS reads my column as a character variable. Then, when I convert the variable from character to numeric, SAS creates a NOTE for invalid arguments, which are the NA's. Because that is exactly what I need (to convert NA's to missing) I do not need to do anything about it.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Mar 2021 21:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/722996#M224280</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-03-02T21:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: reading data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/723002#M224285</link>
      <description>May I ask that what is the role of LEFT in var1_num=input(left(var1),32.)&lt;BR /&gt;and how this code is different from var1_num=input(var1,best32.)?&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Tue, 02 Mar 2021 22:00:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/723002#M224285</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-03-02T22:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: reading data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/723004#M224287</link>
      <description>Left() aligns a character value to the left, if it has extra spaces this can be necessary or the format may truncate the data if it's got 32 leading spaces. &lt;BR /&gt;&lt;BR /&gt;Documentation link for LEFT() function:&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n1awii5zy0u6g0n1fy6yu1hwqiw4.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n1awii5zy0u6g0n1fy6yu1hwqiw4.htm&amp;amp;locale=en&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;FYI - I recommend bookmarking the Functions by Category and formats by category pages in SAS documentation. They get used quite often and are a great resource.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm&amp;amp;locale=en&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Mar 2021 22:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/723004#M224287</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-02T22:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: reading data from Excel (xlsx) to SAS-character/numeric exchange with correct decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/723006#M224289</link>
      <description>What you should do is conditionally handle those so you don't get a message. &lt;BR /&gt;&lt;BR /&gt;if variableValue = "NA" then newValue=.;&lt;BR /&gt;else newValue = input(variableValue, best.);&lt;BR /&gt;&lt;BR /&gt;Or use the IFN/IFC() function which is slightly more compact. But it's much better way to handle this issue.</description>
      <pubDate>Tue, 02 Mar 2021 22:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-data-from-Excel-xlsx-to-SAS-character-numeric-exchange/m-p/723006#M224289</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-02T22:11:26Z</dc:date>
    </item>
  </channel>
</rss>

