<?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 SAS informat wont read datetime with military time (mm/dd/yy hh:mm) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-informat-wont-read-datetime-with-military-time-mm-dd-yy-hh/m-p/552647#M153625</link>
    <description>&lt;P&gt;Hey guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Working with longitudinal data with lots of admission/discharge times. The data is entered into the .csv file as date + military time in the same cell, for example: 01/03/2011 0534.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Trying ti get SAS to read the whole entry but it only reads the date part, ignores the time. It autimatically assigns the format 'MMDDYY10' to these date-time columns. Tried to use various date-time informats to no avail, keep getting an error. Also tried to use the 'Picture statement' in PROC FORMAT to customize my own date-time variable. SAS wont budge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a copy of my code:&lt;/P&gt;&lt;P&gt;FILENAME REFFILE '/folders/myshortcuts/SAS/PIMs.csv';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Define your own date-time format using a date-time "Picture" options*/&lt;BR /&gt;proc format;&lt;BR /&gt;picture Nada other= '%0m/%0d/%Y %0H%0M' (datatype=datetime);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data WORK.PIMs ;&lt;BR /&gt;%let _EFIERR_ = 0; /* set the ERROR detection macro variable */&lt;BR /&gt;infile REFFILE delimiter = ',' MISSOVER DSD firstobs=2 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;informat Arrv_Date_Time datetime_20. ;&lt;BR /&gt;informat Disch_Date_Time MDYAMPM25. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;format Arrv_Date_Time Nada. ;&lt;BR /&gt;format Disch_Date_Time Nada. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;input&lt;BR /&gt;Arrv_Date_Time&lt;BR /&gt;Disch_Date_Time&lt;BR /&gt;;&lt;BR /&gt;if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;___________________________________________________________________________________________________________&lt;/P&gt;&lt;P&gt;Any input is much appreciated, thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nada&lt;/P&gt;</description>
    <pubDate>Sat, 20 Apr 2019 17:50:54 GMT</pubDate>
    <dc:creator>Nmsh</dc:creator>
    <dc:date>2019-04-20T17:50:54Z</dc:date>
    <item>
      <title>SAS informat wont read datetime with military time (mm/dd/yy hh:mm)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-informat-wont-read-datetime-with-military-time-mm-dd-yy-hh/m-p/552647#M153625</link>
      <description>&lt;P&gt;Hey guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Working with longitudinal data with lots of admission/discharge times. The data is entered into the .csv file as date + military time in the same cell, for example: 01/03/2011 0534.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Trying ti get SAS to read the whole entry but it only reads the date part, ignores the time. It autimatically assigns the format 'MMDDYY10' to these date-time columns. Tried to use various date-time informats to no avail, keep getting an error. Also tried to use the 'Picture statement' in PROC FORMAT to customize my own date-time variable. SAS wont budge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a copy of my code:&lt;/P&gt;&lt;P&gt;FILENAME REFFILE '/folders/myshortcuts/SAS/PIMs.csv';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Define your own date-time format using a date-time "Picture" options*/&lt;BR /&gt;proc format;&lt;BR /&gt;picture Nada other= '%0m/%0d/%Y %0H%0M' (datatype=datetime);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data WORK.PIMs ;&lt;BR /&gt;%let _EFIERR_ = 0; /* set the ERROR detection macro variable */&lt;BR /&gt;infile REFFILE delimiter = ',' MISSOVER DSD firstobs=2 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;informat Arrv_Date_Time datetime_20. ;&lt;BR /&gt;informat Disch_Date_Time MDYAMPM25. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;format Arrv_Date_Time Nada. ;&lt;BR /&gt;format Disch_Date_Time Nada. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;input&lt;BR /&gt;Arrv_Date_Time&lt;BR /&gt;Disch_Date_Time&lt;BR /&gt;;&lt;BR /&gt;if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;___________________________________________________________________________________________________________&lt;/P&gt;&lt;P&gt;Any input is much appreciated, thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nada&lt;/P&gt;</description>
      <pubDate>Sat, 20 Apr 2019 17:50:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-informat-wont-read-datetime-with-military-time-mm-dd-yy-hh/m-p/552647#M153625</guid>
      <dc:creator>Nmsh</dc:creator>
      <dc:date>2019-04-20T17:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS informat wont read datetime with military time (mm/dd/yy hh:mm)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-informat-wont-read-datetime-with-military-time-mm-dd-yy-hh/m-p/553091#M153773</link>
      <description>&lt;P&gt;SAS easily reads 24h-clock times, but has no provisions for reading times with no separator, so you need to transform the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are two examples of options you have, one uses a custom informat to do the transformation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;  
  invalue val2dtm 's/(.{10}) (\d\d)(\d\d)/\1:\2:\3/' (regexpe)=[anydtdtm.];
run;

data HAVE;
  A='01/03/2011 0534';  
  B=input(A,val2dtm.);    
  putlog B= datetime20.;
run;

data HAVE;
  A='01/03/2011 0534'; 
  B=prxchange('s/(\d\d).(\d\d).(\d{4}).(\d\d)(\d\d)/\3-\1-\2T\4:\5/',1,A);
  C=input(B,e8601dt.);;
  putlog C= datetime20.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;B=01MAR2011:05:03:00&lt;BR /&gt;C=03JAN2011:05:34:00&lt;/P&gt;
&lt;P&gt;(My locale uses a default data format of dd/mm/yyyy, but the code above translates your date as mm/dd/yyyy since that's what you use)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 00:14:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-informat-wont-read-datetime-with-military-time-mm-dd-yy-hh/m-p/553091#M153773</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-04-23T00:14:59Z</dc:date>
    </item>
  </channel>
</rss>

