<?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: Creating a datetime variable with numeric date and char time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-datetime-variable-with-numeric-date-and-char-time/m-p/642360#M191600</link>
    <description>&lt;P&gt;Did you mean FROM instead of WITH?&lt;/P&gt;
&lt;P&gt;A date value is a number of days since 1960.&amp;nbsp; A time value is number of seconds since midnight.&amp;nbsp;A datetime value is a number of seconds since 1960.&amp;nbsp; To build a datetime value from a date and time value use the DHMS() function. Day,Hours,Minutes,Seconds.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datetime=dhms(date,0,0,time);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To convert you string into a time value using the TIME informat.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;time=input(string,time20.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your number does NOT look like a date, unless you have attached the YYMMDD8. format (or one of the other date type formats that display dates in that pattern).&amp;nbsp; The number&amp;nbsp;20,200,423 would be in the year 57,265.&amp;nbsp; SAS formats only work with 4 digit years.&lt;/P&gt;
&lt;P&gt;So you probably need to first convert that number into an actual date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=input(put(number,z8.),yymmdd8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So putting them together you get:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  datetime=dhms(input(put(number,z8.),yymmdd8.),0,0,input(string,time20.));
  format datetime datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Make sure you attach a datetime type format to your new variable so the values print in way that humans will recognize.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Apr 2020 18:32:47 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-04-23T18:32:47Z</dc:date>
    <item>
      <title>Creating a datetime variable with numeric date and char time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-datetime-variable-with-numeric-date-and-char-time/m-p/642354#M191596</link>
      <description>&lt;P&gt;I want to create a datetime variable with numeric date and char time show below.&amp;nbsp; Would anyone please help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date variable (Numeric) :&amp;nbsp; &amp;nbsp;20200423&lt;/P&gt;&lt;P&gt;Time variable (String):&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14:21:17.7100000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 18:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-datetime-variable-with-numeric-date-and-char-time/m-p/642354#M191596</guid>
      <dc:creator>Fae</dc:creator>
      <dc:date>2020-04-23T18:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a datetime variable with numeric date and char time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-datetime-variable-with-numeric-date-and-char-time/m-p/642360#M191600</link>
      <description>&lt;P&gt;Did you mean FROM instead of WITH?&lt;/P&gt;
&lt;P&gt;A date value is a number of days since 1960.&amp;nbsp; A time value is number of seconds since midnight.&amp;nbsp;A datetime value is a number of seconds since 1960.&amp;nbsp; To build a datetime value from a date and time value use the DHMS() function. Day,Hours,Minutes,Seconds.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datetime=dhms(date,0,0,time);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To convert you string into a time value using the TIME informat.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;time=input(string,time20.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your number does NOT look like a date, unless you have attached the YYMMDD8. format (or one of the other date type formats that display dates in that pattern).&amp;nbsp; The number&amp;nbsp;20,200,423 would be in the year 57,265.&amp;nbsp; SAS formats only work with 4 digit years.&lt;/P&gt;
&lt;P&gt;So you probably need to first convert that number into an actual date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=input(put(number,z8.),yymmdd8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So putting them together you get:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  datetime=dhms(input(put(number,z8.),yymmdd8.),0,0,input(string,time20.));
  format datetime datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Make sure you attach a datetime type format to your new variable so the values print in way that humans will recognize.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 18:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-datetime-variable-with-numeric-date-and-char-time/m-p/642360#M191600</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-23T18:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a datetime variable with numeric date and char time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-datetime-variable-with-numeric-date-and-char-time/m-p/642361#M191601</link>
      <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/201239" target="_blank"&gt;Fae&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do it like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   date = 20200423;
   time = '14:21:17.7100000';

   date1 = input(put(date,8.),yymmdd8.);
   put date1= date9.;

   time1 = input(time,time16.7);
   put time1= time16.7;

   dt = date1*60*60*24 + time1;
   put dt=datetime24.7;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or combining all steps together:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   date = 20200423;
   time = '14:21:17.7100000';

   dt = input(put(date,8.),yymmdd8.)*84400 + input(time,time16.7);
   put dt=datetime24.7;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 18:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-datetime-variable-with-numeric-date-and-char-time/m-p/642361#M191601</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2020-04-23T18:33:21Z</dc:date>
    </item>
  </channel>
</rss>

