<?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: Infile CSV Issue with Date Time Format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625460#M184351</link>
    <description>Hi,&lt;BR /&gt;  I suggest that you experiment with the DATESTYLE option as outlined in the documentation first.&lt;BR /&gt;Cynthia</description>
    <pubDate>Mon, 17 Feb 2020 21:53:25 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2020-02-17T21:53:25Z</dc:date>
    <item>
      <title>Infile CSV Issue with Date Time Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625433#M184332</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using SAS 9.4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a csv file where all the date/time values are m/dd/yy h:mm and they aren't importing correctly even if using the anydtdtm format.&amp;nbsp; This makes sense of course because the month could be 1 or 2 characters as could the days.&amp;nbsp; &amp;nbsp;But how do I fix this other than importing as text and parsing out each date/time component and then building the fields again.&amp;nbsp; I know how to do the latter, was just hoping there was something easier.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any and all assistance appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 20:28:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625433#M184332</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2020-02-17T20:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: Infile CSV Issue with Date Time Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625440#M184337</link>
      <description>&lt;P&gt;Sample data please.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 20:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625440#M184337</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-02-17T20:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Infile CSV Issue with Date Time Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625452#M184346</link>
      <description>&lt;P&gt;I was wrong...if I open the file in Notepad then it shows as one would expect:&amp;nbsp; mmddyy hh:mm:ss so it's unclear why it wouldn't be importing correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;04/03/18 17:00:00 imports as March 4, 2018 instead of April 3, 2018.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 21:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625452#M184346</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2020-02-17T21:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: Infile CSV Issue with Date Time Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625454#M184347</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Without seeing your data and your code, ALL of your code, it's hard to comment. This worked for me. I'm not understanding the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="anydtdtm_fakedata.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36197i638B8C98B0A25C37/image-size/large?v=v2&amp;amp;px=999" role="button" title="anydtdtm_fakedata.png" alt="anydtdtm_fakedata.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 21:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625454#M184347</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-02-17T21:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: Infile CSV Issue with Date Time Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625455#M184348</link>
      <description>&lt;P&gt;Mine comes out as April 3:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Editted below&amp;nbsp; (I sent the first versino, not the final version.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t;
  input dt1 anydtdtm.;
  put dt1=datetime20.;
datalines;
04/03/18 17:00:00
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which produces in the log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;64   data t;
65     input dt1 anydtdtm.;
66     put dt1=datetime20.;
67   datalines;

dt1=03APR2018:17:00:00&lt;BR /&gt;
NOTE: The data set WORK.T has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is the LOCALE of your system,&amp;nbsp; mine is&amp;nbsp;LOCALE=EN_US. &amp;nbsp; You can see yours via this program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc options option=locale;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 21:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625455#M184348</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-02-17T21:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Infile CSV Issue with Date Time Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625457#M184349</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Interesting, it works for me:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="anydtdtm2.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36198iED0B09E8ACC7A96A/image-size/large?v=v2&amp;amp;px=999" role="button" title="anydtdtm2.png" alt="anydtdtm2.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you might check the doc and the DATESTYLE option. The ANYDTDTM doc says:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="doc_note.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36199i32524CBBF2EF6BBE/image-size/large?v=v2&amp;amp;px=999" role="button" title="doc_note.png" alt="doc_note.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the value of my DATESTYLE option is MDY.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 21:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625457#M184349</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-02-17T21:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: Infile CSV Issue with Date Time Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625458#M184350</link>
      <description>&lt;P&gt;Thanks Cynthia.&amp;nbsp; I did exactly as you did in your example with my data, including the format in the proc print and it is not correctly recognizing the date/time even though the format is standard.&amp;nbsp; I guess I'm going to have to import as string and create the date/time values from there.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 21:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625458#M184350</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2020-02-17T21:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: Infile CSV Issue with Date Time Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625460#M184351</link>
      <description>Hi,&lt;BR /&gt;  I suggest that you experiment with the DATESTYLE option as outlined in the documentation first.&lt;BR /&gt;Cynthia</description>
      <pubDate>Mon, 17 Feb 2020 21:53:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625460#M184351</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-02-17T21:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: Infile CSV Issue with Date Time Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625463#M184353</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Okay, I found out that my datestyle is dmy thus the issue i'm having.&amp;nbsp; How do i change it?&amp;nbsp; Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 22:04:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625463#M184353</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2020-02-17T22:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: Infile CSV Issue with Date Time Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625467#M184354</link>
      <description>&lt;P&gt;For anyone else looking at this thread, the issue was my datestyle option as Cynthia surmised.&amp;nbsp; Thanks Cynthia!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I first looked at what my datestyle was:&amp;nbsp; proc options option=datestyle;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once I confirmed it was dmy I entered options datastyle=mdy; to change it to the format I wanted.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 22:14:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625467#M184354</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2020-02-17T22:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: Infile CSV Issue with Date Time Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625476#M184359</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15342"&gt;@shellp55&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;For anyone else looking at this thread, the issue was my datestyle option as Cynthia surmised.&amp;nbsp; Thanks Cynthia!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I first looked at what my datestyle was:&amp;nbsp; proc options option=datestyle;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once I confirmed it was dmy I entered options datastyle=mdy; to change it to the format I wanted.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just to clarify a little.&amp;nbsp; The reason the DATESTYLE option has any impact is because you are using a guessing procedure, the ANYDTDTM informat, so SAS has to guess whether 10/12 is Octobter 12th or 10th of December.&amp;nbsp; The DATESTYLE setting is how the ANYDTxxx informats decide which date is meant.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are two causes for why you had to use the guessing procedure.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The main one is that the file was generated in an ambiguous style.&lt;/STRONG&gt;&amp;nbsp; If the values had been presented in Y-M-D order or in ddMONyyyy order then there would have been no way to mistake them. &lt;STRONG&gt;Note also that your date values only include two digits for the year.&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;So what year does 18 represent? is that 2018 or 1918&amp;nbsp; or 1818 or&amp;nbsp; 2118 or ??.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The secondary one is that while SAS does have a format for reading datetimes with the date in MDY order (MDYAMPM) it does not have one to read them in DMY order (perhaps they should make a DMYAMPM informat?).&amp;nbsp; So users are forced to use the guessing information instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are lucky and the dates are in fact in MDY order then use the MDYAMPM informat and avoid the guessing.&lt;/P&gt;
&lt;PRE&gt;399   data t;
400     input @1 dt1 anydtdtm20. @1 dt2 mdyampm20. @1 dt3 dmyampm20.;
                                                          ----------
                                                          485
NOTE 485-185: Informat DMYAMPM was not found or could not be loaded.

401     put (dt:) (=datetime20.);
402   datalines;

NOTE: Invalid data for dt3 in line 403 1-8.
dt1=03APR2018:17:00:00 dt2=03APR2018:17:00:00 dt3=.
RULE:       ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+
403         04/03/18 17:00:00
dt1=1838394000 dt2=1838394000 dt3=. _ERROR_=1 _N_=1
NOTE: The data set WORK.T has 1 observations and 3 variables.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 00:56:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625476#M184359</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-18T00:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: Infile CSV Issue with Date Time Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625481#M184362</link>
      <description>&lt;P&gt;I knew that it impacted the "any date" options but I didn't know what informat to select for the data format I had.&amp;nbsp; The information you provided is really helpful, thanks so much for posting!&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 01:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625481#M184362</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2020-02-18T01:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: Infile CSV Issue with Date Time Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625484#M184364</link>
      <description>&lt;P&gt;You should really check if you can get whoever sent you the file to fix it.&amp;nbsp; Those &lt;STRONG&gt;two digit years&lt;/STRONG&gt; are especially going to be a problem.&amp;nbsp; A lot of SAS users were surprised in January of 2020 that reading the 7 character SYSDATE macro variable made it look like their jobs ran in 1920! They were still running with YEARCUTOFF option set to 1920.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 01:31:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625484#M184364</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-18T01:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: Infile CSV Issue with Date Time Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625530#M184380</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15342"&gt;@shellp55&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I was wrong...if I open the file in Notepad then it shows as one would expect:&amp;nbsp; mmddyy hh:mm:ss so it's unclear why it wouldn't be importing correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;04/03/18 17:00:00 imports as March 4, 2018 instead of April 3, 2018.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'd rather read that as March 18, 2004.&lt;/P&gt;
&lt;P&gt;This just illustrates the stupidity of not using ISO-formatted dates and times, and (still!) using 2-digit years. After the Y2K scare, this makes me doubt my faith in the future of mankind.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 07:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-CSV-Issue-with-Date-Time-Format/m-p/625530#M184380</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-18T07:56:26Z</dc:date>
    </item>
  </channel>
</rss>

