<?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: Converting a datetime into a date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-datetime-into-a-date/m-p/421068#M103593</link>
    <description>&lt;P&gt;Regular expression are really only useful for parsing text, not numbers. Dates as stored as the number of days since '01JAN1960'd. Datetimes are stored as the number of seconds since '01JAN1960:00:00'dt.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DATEPART() and TIMEPART() functions can be used to tease out the parts of a datetime value.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=datepart(dt);
time=timepart(dt);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use the DHMS() function to create a datetime value from date and time values. Note you can just set the Day and Hour arguments to zero and put the time value into the Seconds.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dt=dhms(date,0,0,time)&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It would make no sense to convert the number of seconds stored in your datetime variable into a character string that would represent that number of seconds and then try to read it is if any of the digits represented year, month or day numbers.&amp;nbsp; But you could convert it to a string that looks like a date and then use the appropriate informat to convert that string back to a date. For example you could use the DTDATE9. format and the DATE9. informat.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=input(put(dt,dtdate9.),date9.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also if you don't need the time value they why store it to begin with?&amp;nbsp; You could change you original code from using the ANYDTDTM informat to use the ANYDTDTE informat instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Dec 2017 03:39:27 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-12-14T03:39:27Z</dc:date>
    <item>
      <title>Converting a datetime into a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-datetime-into-a-date/m-p/420941#M103564</link>
      <description>&lt;P&gt;I have a CSV file with a column with a date format of MM/DD/YYYY HH:MM that I would like to convert to MM/DD/YYYY.&amp;nbsp; This is pretty painless in Python but haven't been able to figure it out in SAS.&amp;nbsp; My data step looks something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data foo;
	infile &amp;lt;path&amp;gt; delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2;
	informat ID best32. ;
	informat DATE anydtdtm40. ;
	format ID best12. ;
	format DATE datetime. ;
	input
		ID
		DATE;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I figure I can do something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATE = INPUT(PUT(DATE, 8.), MMDDYY10.);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But the number are too big, ~1.8E9, for it to be a valid value for the input function.&amp;nbsp; I'm thinking of using regular expressions to cut off the time part?&amp;nbsp; That's all I can think of.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 19:09:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-datetime-into-a-date/m-p/420941#M103564</guid>
      <dc:creator>tomcmacdonald</dc:creator>
      <dc:date>2017-12-13T19:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a datetime into a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-datetime-into-a-date/m-p/420945#M103566</link>
      <description>&lt;PRE&gt;data foo;
	infile &amp;lt;path&amp;gt; delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2;
	informat ID best32. ;
	informat DATE anydtdtm40. ;
	format ID best12. ;
	format DATE datetime. ;
  want=datepart(date);
  format want mmddyy10.;
	input
		ID
		DATE;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 19:06:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-datetime-into-a-date/m-p/420945#M103566</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-13T19:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a datetime into a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-datetime-into-a-date/m-p/421068#M103593</link>
      <description>&lt;P&gt;Regular expression are really only useful for parsing text, not numbers. Dates as stored as the number of days since '01JAN1960'd. Datetimes are stored as the number of seconds since '01JAN1960:00:00'dt.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DATEPART() and TIMEPART() functions can be used to tease out the parts of a datetime value.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=datepart(dt);
time=timepart(dt);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use the DHMS() function to create a datetime value from date and time values. Note you can just set the Day and Hour arguments to zero and put the time value into the Seconds.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dt=dhms(date,0,0,time)&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It would make no sense to convert the number of seconds stored in your datetime variable into a character string that would represent that number of seconds and then try to read it is if any of the digits represented year, month or day numbers.&amp;nbsp; But you could convert it to a string that looks like a date and then use the appropriate informat to convert that string back to a date. For example you could use the DTDATE9. format and the DATE9. informat.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=input(put(dt,dtdate9.),date9.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also if you don't need the time value they why store it to begin with?&amp;nbsp; You could change you original code from using the ANYDTDTM informat to use the ANYDTDTE informat instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 03:39:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-datetime-into-a-date/m-p/421068#M103593</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-14T03:39:27Z</dc:date>
    </item>
  </channel>
</rss>

