<?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: Transforming a string to become a datetime value in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5108#M2069</link>
    <description>Here's my solution. Use substr to extract the date part of the string and the time part of the string into two variables. Then use the input function with the mmddyy10. informat to convert the date string to a SAS date value, and with the time8. informat to convert the time string to a SAS time value.&lt;BR /&gt;
&lt;BR /&gt;
Given a SAS date value and a SAS time value, the SAS documentation for the DHMS function explains how to combine them into a SAS datetime value.&lt;BR /&gt;
&lt;BR /&gt;
Here's a data step to test my algorithm:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   input str $20.;&lt;BR /&gt;
   dtstr = substr(str, 1, 10);&lt;BR /&gt;
   tmstr = substr(str, 12, 8);&lt;BR /&gt;
&lt;BR /&gt;
   dt = input(dtstr, mmddyy10.);&lt;BR /&gt;
   tm = input(tmstr, time8.);&lt;BR /&gt;
&lt;BR /&gt;
   dttm = dhms(dt, 0, 0, tm);&lt;BR /&gt;
   put dttm datetime19.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
10/16/2007 22:37:30&lt;BR /&gt;
05/01/1953 11:15:27&lt;BR /&gt;
07/04/1976 23:59:59&lt;BR /&gt;
12/31/2000 00:00:00&lt;BR /&gt;
run;[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Please test this for yourself to make sure it works.</description>
    <pubDate>Wed, 17 Oct 2007 17:08:44 GMT</pubDate>
    <dc:creator>Tim_SAS</dc:creator>
    <dc:date>2007-10-17T17:08:44Z</dc:date>
    <item>
      <title>Transforming a string to become a datetime value</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5107#M2068</link>
      <description>I have a dataset with a string variable that has this appearance : "10/16/2007 22:37:30". I would like to convert this string to become a datetime value. I read that the datetime format is this 16Oct2007:22:37:30 but I was trying to create a date and a time variable from the string using the substrn function and then join them to create my datetime variable, all that in a data step&lt;BR /&gt;
&lt;BR /&gt;
Im unable to do it, I though it would be a great idea to ask here about the pertinence of my technique before trying to make it work that way, do you guys have any tips on the best way to do this ?&lt;BR /&gt;
&lt;BR /&gt;
cheers&lt;BR /&gt;
Yan</description>
      <pubDate>Wed, 17 Oct 2007 03:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5107#M2068</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-10-17T03:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming a string to become a datetime value</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5108#M2069</link>
      <description>Here's my solution. Use substr to extract the date part of the string and the time part of the string into two variables. Then use the input function with the mmddyy10. informat to convert the date string to a SAS date value, and with the time8. informat to convert the time string to a SAS time value.&lt;BR /&gt;
&lt;BR /&gt;
Given a SAS date value and a SAS time value, the SAS documentation for the DHMS function explains how to combine them into a SAS datetime value.&lt;BR /&gt;
&lt;BR /&gt;
Here's a data step to test my algorithm:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   input str $20.;&lt;BR /&gt;
   dtstr = substr(str, 1, 10);&lt;BR /&gt;
   tmstr = substr(str, 12, 8);&lt;BR /&gt;
&lt;BR /&gt;
   dt = input(dtstr, mmddyy10.);&lt;BR /&gt;
   tm = input(tmstr, time8.);&lt;BR /&gt;
&lt;BR /&gt;
   dttm = dhms(dt, 0, 0, tm);&lt;BR /&gt;
   put dttm datetime19.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
10/16/2007 22:37:30&lt;BR /&gt;
05/01/1953 11:15:27&lt;BR /&gt;
07/04/1976 23:59:59&lt;BR /&gt;
12/31/2000 00:00:00&lt;BR /&gt;
run;[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Please test this for yourself to make sure it works.</description>
      <pubDate>Wed, 17 Oct 2007 17:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5108#M2069</guid>
      <dc:creator>Tim_SAS</dc:creator>
      <dc:date>2007-10-17T17:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming a string to become a datetime value</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5109#M2070</link>
      <description>Thank you Tim&lt;BR /&gt;
&lt;BR /&gt;
meanwhile someone also provided me this way of acheiving the desired result using the scan function instead of substr :&lt;BR /&gt;
&lt;BR /&gt;
This works :&lt;BR /&gt;
Data _null_ ;&lt;BR /&gt;
%let entry_date_time_orig = "10/13/2007 01:14:35" ;&lt;BR /&gt;
entry_date_time=sum((input(scan(&amp;amp;entry_date_time_orig.,1,' '),mmddyy10.)*60*60*24),input(scan(&amp;amp;entry_date_time_orig.,2,' '),time8.));&lt;BR /&gt;
put entry_date_time=datetime.;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 17 Oct 2007 17:58:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5109#M2070</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-10-17T17:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming a string to become a datetime value</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5110#M2071</link>
      <description>try informat   mdyampm.&lt;BR /&gt;
like&lt;BR /&gt;
&lt;BR /&gt;
%put %sysfunc( inputn( 10/13/2007 01:14:35, mdyampm), datetime);&lt;BR /&gt;
&lt;BR /&gt;
PeterC</description>
      <pubDate>Wed, 17 Oct 2007 21:38:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5110#M2071</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2007-10-17T21:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming a string to become a datetime value</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5111#M2072</link>
      <description>hi guys.. &lt;BR /&gt;
&lt;BR /&gt;
how about if the input is not a string. but date9. values.&lt;BR /&gt;
i have a variable contain a date type : yymmdd10. &lt;BR /&gt;
and i want to make a type datetime19.&lt;BR /&gt;
ex : position_date is =&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
==================================================&lt;BR /&gt;
data _null_;&lt;BR /&gt;
       %put &amp;amp;position_date;&lt;BR /&gt;
	myDate = input(symget('position_date'),yymmdd10.);&lt;BR /&gt;
	format myDate datetime19.;&lt;BR /&gt;
	put myDate=;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
the log result :&lt;BR /&gt;
&lt;BR /&gt;
994  data _null_;&lt;BR /&gt;
995      %put &amp;amp;position_date;&lt;BR /&gt;
2008-03-31&lt;BR /&gt;
996      myDate = input(symget('position_date'),yymmdd10.);&lt;BR /&gt;
997      format myDate datetime19.;&lt;BR /&gt;
998      put myDate=;&lt;BR /&gt;
999  run;&lt;BR /&gt;
&lt;BR /&gt;
myDate=01JAN1960:04:53:42&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.03 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
==============================================&lt;BR /&gt;
&lt;BR /&gt;
why myDate became : 01JAN1960:04:53:42 not 31MAR2008:00:00:00 ?&lt;BR /&gt;
how to make a date like that?&lt;BR /&gt;
&lt;BR /&gt;
thank you.&lt;BR /&gt;
regards&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
capricornday</description>
      <pubDate>Mon, 18 May 2009 08:11:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5111#M2072</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-18T08:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming a string to become a datetime value</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5112#M2073</link>
      <description>sas datetime formats are suitable for datetime values, not date values.&lt;BR /&gt;
Convert from a numeric date value to datetime value with function dhms(), like[pre]      myDateTime = DHMS( myDate, 0,0,0 ) ; [/pre] Before reading the doc for the datetime() function &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000179419.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000179419.htm&lt;/A&gt; , I think you should read up on how SAS manages dates and times in the Concepts section at  &lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002200738.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002200738.htm&lt;/A&gt;.&lt;BR /&gt;
 &lt;BR /&gt;
Good Luck&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Mon, 18 May 2009 11:37:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5112#M2073</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-05-18T11:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming a string to become a datetime value</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5113#M2074</link>
      <description>Thanks  Peter.C&lt;BR /&gt;
your links also usefull for me. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
regards'&lt;BR /&gt;
capricornday</description>
      <pubDate>Tue, 19 May 2009 04:34:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Transforming-a-string-to-become-a-datetime-value/m-p/5113#M2074</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-19T04:34:04Z</dc:date>
    </item>
  </channel>
</rss>

