<?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 Date variable that contains hours (31/12/2015  5:45:00 PM) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258808#M49931</link>
    <description>&lt;P&gt;To further explain what my version does:&lt;/P&gt;
&lt;P&gt;The DLM=',' option sets the delimiter. By not using a format in the INPUT statement, I give SAS free hand in snipping the input line into columns (formatted input prevents this, as each format reads exactly the number of bytes specified by the format length, and delimiters are ignored).&lt;/P&gt;
&lt;P&gt;Since I specified the date-only informat for Created_On, the remaining bytes of that column in the infile are simply discarded.&lt;/P&gt;
&lt;P&gt;If you also want to read the time, read the whole input column into a character variable, split it with SCAN(), and use the INPUT() function with proper informats on the slices to convert to date/time.&lt;/P&gt;</description>
    <pubDate>Thu, 24 Mar 2016 14:10:22 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-03-24T14:10:22Z</dc:date>
    <item>
      <title>Importing Date variable that contains hours (31/12/2015  5:45:00 PM)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258787#M49919</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to import data using the &lt;STRONG&gt;data step and infile,&lt;/STRONG&gt; however one of my data fields has the format '&lt;STRONG&gt;31/12/2015 &amp;nbsp;5:45:00 PM&lt;/STRONG&gt;'.&lt;/P&gt;&lt;P&gt;How can I tell SAS to read this as a date (&lt;U&gt;preferably remove time all together&lt;/U&gt;).&lt;/P&gt;&lt;P&gt;Ive tried the following.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data testdata;&lt;/P&gt;&lt;P&gt;infile 'filepath' dsd;&lt;/P&gt;&lt;P&gt;input Date DDMMYY10.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but Im guessing I need a different Date format, as this gives me an error in the log?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2016 13:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258787#M49919</guid>
      <dc:creator>Chaseg22</dc:creator>
      <dc:date>2016-03-24T13:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Date variable that contains hours (31/12/2015  5:45:00 PM)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258788#M49920</link>
      <description>&lt;P&gt;If your data looks exactly like your example, your code should work. Please post the ERROR message and preceding code from the log&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2016 13:12:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258788#M49920</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-03-24T13:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Date variable that contains hours (31/12/2015  5:45:00 PM)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258799#M49923</link>
      <description>&lt;P&gt;Here is the exact code I am using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data testing;&lt;BR /&gt;infile 'C:\Users\****\Desktop\SAStest.csv' dlm=',' firstobs=2 dsd;&lt;BR /&gt;input Case_Number $ Created_On DDMMYY10. Location $16.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the error&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NOTE: Increase available buffer lines with the INFILE n= option.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Case_Number=Cas 1 Created_On=. Location=Cas 2,12/26/2015 _ERROR_=1 _N_=1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;NOTE: Invalid data for Created_On in line 4 7-16.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5 Cas 4,12/23/2015 10:27,Victoria 31&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2016 13:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258799#M49923</guid>
      <dc:creator>Chaseg22</dc:creator>
      <dc:date>2016-03-24T13:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Date variable that contains hours (31/12/2015  5:45:00 PM)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258802#M49925</link>
      <description>Im guessing it has to do with the raw data.&lt;BR /&gt;12/23/2015 10:27&lt;BR /&gt;Sas isnt reading this as a date, even with the ANYDTDTM10. format I get the Invalid data for Created_On in line 63 8-17.&lt;BR /&gt;Error.&lt;BR /&gt;Any way around this?</description>
      <pubDate>Thu, 24 Mar 2016 14:02:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258802#M49925</guid>
      <dc:creator>Chaseg22</dc:creator>
      <dc:date>2016-03-24T14:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Date variable that contains hours (31/12/2015  5:45:00 PM)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258803#M49926</link>
      <description>&lt;P&gt;OK, so it's clear. You mixed list and formatted input, which usually fails. Happens to everyone at least once &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testing;
informat Created_On mmddyy10.;
length Location $16;&lt;BR /&gt;format Created_On mmddyy10.;
infile
  'C:\Users\****\Desktop\SAStest.csv'
  dlm=','
  firstobs=2
  dsd
;
input
  Case_Number $
  Created_On
  Location
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Mar 2016 14:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258803#M49926</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-03-24T14:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Date variable that contains hours (31/12/2015  5:45:00 PM)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258804#M49927</link>
      <description>Thank you Kurt.&lt;BR /&gt;</description>
      <pubDate>Thu, 24 Mar 2016 14:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258804#M49927</guid>
      <dc:creator>Chaseg22</dc:creator>
      <dc:date>2016-03-24T14:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Date variable that contains hours (31/12/2015  5:45:00 PM)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258808#M49931</link>
      <description>&lt;P&gt;To further explain what my version does:&lt;/P&gt;
&lt;P&gt;The DLM=',' option sets the delimiter. By not using a format in the INPUT statement, I give SAS free hand in snipping the input line into columns (formatted input prevents this, as each format reads exactly the number of bytes specified by the format length, and delimiters are ignored).&lt;/P&gt;
&lt;P&gt;Since I specified the date-only informat for Created_On, the remaining bytes of that column in the infile are simply discarded.&lt;/P&gt;
&lt;P&gt;If you also want to read the time, read the whole input column into a character variable, split it with SCAN(), and use the INPUT() function with proper informats on the slices to convert to date/time.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2016 14:10:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258808#M49931</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-03-24T14:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Date variable that contains hours (31/12/2015  5:45:00 PM)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258873#M49963</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Since I specified the date-only informat for Created_On, the remaining bytes of that column in the infile are simply discarded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm under the impression it's not that simple. If I add AM or PM after the time part (as suggested by the&amp;nbsp;initial post), I get "Invalid data" messages and missing values. It's surprising enough to me that MMDDYY10. used with modified list input (the informat length is ignored in this situation) is able to discard the time part without AM/PM. This is not mentioned in the documentation. Even ANYDTDTE. fails (but without messages in the log!) as soon as AM or PM are added, although the &lt;A href="http://support.sas.com/documentation/cdl/en/syntaxidx/68719/HTML/default/index.htm#/documentation/cdl/en/leforinforref/64790/HTML/default/n04jh1fkv5c8zan14fhqcby7jsu4.htm" target="_blank"&gt;documentation&lt;/A&gt; states the contrary (incorrectly, I think).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Reading the field into a character variable, as you've described, would be the straightforward&amp;nbsp;remedy in case of such problems.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2016 16:59:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/258873#M49963</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-24T16:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Date variable that contains hours (31/12/2015  5:45:00 PM)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/259022#M50033</link>
      <description>&lt;P&gt;You are right. Adding something to the string causes problems, so reading the whole field into character and splitting is the way to go.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 08:01:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Date-variable-that-contains-hours-31-12-2015-5-45-00/m-p/259022#M50033</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-03-25T08:01:14Z</dc:date>
    </item>
  </channel>
</rss>

