<?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: Importing Excel sheet with costum formatted variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-Excel-sheet-with-costum-formatted-variables/m-p/919166#M362057</link>
    <description>&lt;P&gt;Thank you so much for a great response. The code you provided worked in creating a new variable with correct values! I'm still unsure why the conversion to character happened! I made sure no mixed values were in the file before importing! I guess I must've missed something.&lt;/P&gt;
&lt;P&gt;My data also has a Birth Date variable which was treated the same way. What SAS format would work on it?&lt;/P&gt;</description>
    <pubDate>Wed, 06 Mar 2024 17:20:28 GMT</pubDate>
    <dc:creator>Ihsan-Mahdi</dc:creator>
    <dc:date>2024-03-06T17:20:28Z</dc:date>
    <item>
      <title>Importing Excel sheet with costum formatted variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Excel-sheet-with-costum-formatted-variables/m-p/919157#M362052</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I'm trying to read an Excel sheet in SAS using proc import. The sheet has date/time variables formatted as&amp;nbsp;m/d/yyyy h:mm.&lt;/P&gt;
&lt;P&gt;When imported to SAS, the variables are converted to string.&lt;/P&gt;
&lt;P&gt;For example a value in the Excel sheet of:&amp;nbsp;12/31/2020 10:42:00 PM is imported as a character variable with the value:&amp;nbsp;44196.94583333333.&lt;/P&gt;
&lt;P&gt;When I try converting the character variable to numeric, SAS doesn't allow me to apply the DATETIME. format, it only works if I use the format 20. When I apply the DATETIME. format to the newly created numeric variable (formatted 20.), I get the wrong date!&lt;/P&gt;
&lt;P&gt;Is there a way to fix this? Thank you:)&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 16:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Excel-sheet-with-costum-formatted-variables/m-p/919157#M362052</guid>
      <dc:creator>Ihsan-Mahdi</dc:creator>
      <dc:date>2024-03-06T16:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Excel sheet with costum formatted variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Excel-sheet-with-costum-formatted-variables/m-p/919160#M362054</link>
      <description>&lt;P&gt;The column has at least one cell that does NOT have a numeric value in it (Excel stores dates and datetime values are numbers). So SAS had to make a CHARACTER variable so it could store that cell with the character string in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The main fix is to make sure each column in the worksheet uses only one type of values.&amp;nbsp; Either all numbers or all characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you cannot do that then make a new variable in SAS that has a datetime value by converting the strings SAS created to store the raw number of days (and fraction of days) that EXCEL uses to store date (and datetime) values into a number and adjust for the difference in where they start counting (and Excel mistaken inclusion of Feb 29 in the year 1900).&lt;/P&gt;
&lt;P&gt;So for the actual datetime values, like&amp;nbsp;&lt;SPAN&gt;44196.94583333333,&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;this will work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  newvar = dhms(input(oldvar,32.)+'30DEC1899'd,0,0,0);
  format newvar datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But what every gibberish character string was there that made SAS think the column has mixed cell types will probably cause the INPUT() function to fail.&amp;nbsp; So you might need to add some test to see what those values are and decide if they can also be converted into valid datetime values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 17:05:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Excel-sheet-with-costum-formatted-variables/m-p/919160#M362054</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-06T17:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Excel sheet with costum formatted variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Excel-sheet-with-costum-formatted-variables/m-p/919166#M362057</link>
      <description>&lt;P&gt;Thank you so much for a great response. The code you provided worked in creating a new variable with correct values! I'm still unsure why the conversion to character happened! I made sure no mixed values were in the file before importing! I guess I must've missed something.&lt;/P&gt;
&lt;P&gt;My data also has a Birth Date variable which was treated the same way. What SAS format would work on it?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 17:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Excel-sheet-with-costum-formatted-variables/m-p/919166#M362057</guid>
      <dc:creator>Ihsan-Mahdi</dc:creator>
      <dc:date>2024-03-06T17:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Excel sheet with costum formatted variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Excel-sheet-with-costum-formatted-variables/m-p/919208#M362065</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/333045"&gt;@Ihsan-Mahdi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you so much for a great response. The code you provided worked in creating a new variable with correct values! I'm still unsure why the conversion to character happened! I made sure no mixed values were in the file before importing! I guess I must've missed something.&lt;/P&gt;
&lt;P&gt;My data also has a Birth Date variable which was treated the same way. What SAS format would work on it?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you have a DATE column (no time of day component) then skip the DHMS() function and use the DATE format (or any other format you like that works with DATE values).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newvar=input(oldvar,32.)+'30DEC1899'd;
format newvar date9.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Mar 2024 22:06:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Excel-sheet-with-costum-formatted-variables/m-p/919208#M362065</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-06T22:06:37Z</dc:date>
    </item>
  </channel>
</rss>

