<?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 read in time format (like 12:02:27 AM) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/read-in-time-format-like-12-02-27-AM/m-p/243935#M45416</link>
    <description>&lt;PRE&gt;  data WORK.test    ;
    infile 'data.csv' delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
       informat ID $40. ;
       informat CreatedDT anydttme.  ;
       informat EndDT anydttme.  ;
       informat PeriodInDays best32. ;
       informat PeriodType $14. ;
       format ID $40. ;
       format CreatedDT time11. ;
       format EndDT time11. ;
       format PeriodInDays best12. ;
       format PeriodType $14. ;
    input
                ID $
                CreatedDT 
                EndDT 
                PeriodInDays
                PeriodType $
    ;
    run;
&lt;/PRE&gt;
&lt;P&gt;I am using the the above code to read in a csv file, with two time variables in the format like 12:02:27 AM. However, after reading in, these two variables have blank columns, and there is no error message in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;can anyone give some hints?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Jan 2016 21:30:40 GMT</pubDate>
    <dc:creator>fengyuwuzu</dc:creator>
    <dc:date>2016-01-15T21:30:40Z</dc:date>
    <item>
      <title>read in time format (like 12:02:27 AM)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-in-time-format-like-12-02-27-AM/m-p/243935#M45416</link>
      <description>&lt;PRE&gt;  data WORK.test    ;
    infile 'data.csv' delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
       informat ID $40. ;
       informat CreatedDT anydttme.  ;
       informat EndDT anydttme.  ;
       informat PeriodInDays best32. ;
       informat PeriodType $14. ;
       format ID $40. ;
       format CreatedDT time11. ;
       format EndDT time11. ;
       format PeriodInDays best12. ;
       format PeriodType $14. ;
    input
                ID $
                CreatedDT 
                EndDT 
                PeriodInDays
                PeriodType $
    ;
    run;
&lt;/PRE&gt;
&lt;P&gt;I am using the the above code to read in a csv file, with two time variables in the format like 12:02:27 AM. However, after reading in, these two variables have blank columns, and there is no error message in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;can anyone give some hints?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jan 2016 21:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-in-time-format-like-12-02-27-AM/m-p/243935#M45416</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-01-15T21:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: read in time format (like 12:02:27 AM)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-in-time-format-like-12-02-27-AM/m-p/243940#M45418</link>
      <description>&lt;P&gt;I think this will work for you:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;informat time anydtdtm11.;&lt;BR /&gt;format time timeampm11.;&lt;BR /&gt;input time;&lt;BR /&gt;cards;&lt;BR /&gt;12:02:27 AM&lt;BR /&gt;;run;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jan 2016 21:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-in-time-format-like-12-02-27-AM/m-p/243940#M45418</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2016-01-15T21:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: read in time format (like 12:02:27 AM)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-in-time-format-like-12-02-27-AM/m-p/243993#M45424</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30712"&gt;@Steelers_In_DC﻿&lt;/a&gt;: It's true that informat ANYDTDTM11. can read time values of the form HH:MM:SS AM/PM, but your data step does not prove this. You are using modified list input with the default delimiter ' ' (blank). That is, your input statement reads "12:02:27", but not the "AM" after the blank. If you change the "AM" in your data line to "PM" (or to an invalid string such as "XY"), you will see that TIME will continue to show as&amp;nbsp;12:02:27 &lt;STRONG&gt;AM&lt;/STRONG&gt;. You could use the "&amp;amp;" modifier (&lt;FONT face="courier new,courier"&gt;input time &amp;amp;;&lt;/FONT&gt;) or change the delimiter (&lt;FONT face="courier new,courier"&gt;infile cards dlm=',';&lt;/FONT&gt;) or use formatted input (&lt;FONT face="courier new,courier"&gt;input time anydtdtm11.;&lt;/FONT&gt;) to read the value correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/56807"&gt;@fengyuwuzu﻿&lt;/a&gt;: Your code is syntactically correct. Informat ANYDTTME. is a good choice to read values like 12:02:27 AM. (There is no date part to be read, hence no need to apply a datetime informat such as ANYDTDTM., although the result would be the same. You are also right not using a&amp;nbsp;length specification, e.g. "11" in the informat. This would be ignored anyway in the reading process, as you don't use formatted input [cf.&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/syntaxidx/68719/HTML/default/index.htm#/documentation/cdl//en/lestmtsref/68024/HTML/default/p164164hob450kn1agkpcosya669.htm" target="_blank"&gt;documentation of the INFORMAT statement&lt;/A&gt;].)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, the reason why you obtain only missing values for the CreatedDT and EndDT variables will be found&amp;nbsp;&lt;U&gt;in your data&lt;/U&gt;. Please note that the ANYDTTME. informat is very tolerant: Unlike, e.g., the TIME. informat, it does not create "Invalid data ..." messages even if your time value is the string "blahblah".&amp;nbsp;Could you please attach a single line (or a few lines) of your csv file with data, so we can see why it is not being read correctly?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you could temporarily replace &lt;FONT face="courier new,courier"&gt;anydttme.&lt;/FONT&gt; with &lt;FONT face="courier new,courier"&gt;time.&lt;/FONT&gt; in your INFORMAT&amp;nbsp;statements and then post the log messages for your data step. The TIME. informat is also suitable to read values like 12:02:27 AM, but&amp;nbsp;it's more likely to produce an&amp;nbsp;&lt;SPAN&gt;"Invalid data ..." message, if the data are in fact invalid.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jan 2016 14:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-in-time-format-like-12-02-27-AM/m-p/243993#M45424</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-16T14:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: read in time format (like 12:02:27 AM)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-in-time-format-like-12-02-27-AM/m-p/243994#M45425</link>
      <description>&lt;P&gt;The example value you listed works fine for me. &amp;nbsp;Note that I find that it works better to&amp;nbsp;explicitly&amp;nbsp;define the variable types rather than asking SAS to guess how I want them defined by the INFORMAT or FORMAT that I have attached to them. Also attaching INFORMATS or FORMATS like $14. do not add any value and can cause trouble later if want to change the length of the variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.test    ;
    infile cards dsd TRUNCOVER firstobs=2 ;
    length ID $40 CreatedDT EndDT PeriodInDays 8 PeriodType $14 ;
    informat CreatedDT anydttme.  ;
    informat EndDT anydttme.  ;
    format CreatedDT time11. ;
    format EndDT time11. ;
    input ID -- PeriodType ;
    put (_all_) (=);
cards;
ID,CreatedDT,EndDT,PeriodInDays,PeriodType
1,12:02:27 AM,12:02:27 PM,0,test
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here are results for this data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ID=1 CreatedDT=0:02:27 EndDT=12:02:27 PeriodInDays=0 PeriodType=test
NOTE: The data set WORK.TEST has 1 observations and 5 variables.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 16 Jan 2016 15:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-in-time-format-like-12-02-27-AM/m-p/243994#M45425</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-01-16T15:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: read in time format (like 12:02:27 AM)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-in-time-format-like-12-02-27-AM/m-p/244548#M45575</link>
      <description>&lt;P&gt;Note that to display 12:02:27 &lt;STRONG&gt;AM&lt;/STRONG&gt; you want to use a TIMEAMPM11. format, else you get the 0:02:27 time.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 21:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-in-time-format-like-12-02-27-AM/m-p/244548#M45575</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-01-19T21:18:49Z</dc:date>
    </item>
  </channel>
</rss>

