<?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 two date and time variables in one DateTime variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400677#M278678</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dhms(date, 0, 0, input(time, time.))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS stores date as a number, where its the number of days from Jan 1, 1960&lt;/P&gt;
&lt;P&gt;SAS stores datetime as numbers, where it is the number of seconds from Jan 1, 1960&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So yes, you get a number. And then you apply a datetime variable to view it as a datetime but it's still a number.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure if you're using SQL or a data step, but apply a format either way is easy.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	time="12:32";
	date='01Jan2017'd;
	my_date = dhms(date, 0, 0, input(time, time.));
	format my_date datetime21.;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 03 Oct 2017 17:35:35 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-10-03T17:35:35Z</dc:date>
    <item>
      <title>Transforming two date and time variables in one DateTime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400647#M278673</link>
      <description>&lt;P&gt;I'm on SAS Enterprise Guide 7.1, Windows 10.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How does one go about transforming the variables date and time seen below in one DateTime variable?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Q.PNG" style="width: 167px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15574i9D6C1B2B95F8B275/image-size/large?v=v2&amp;amp;px=999" role="button" title="Q.PNG" alt="Q.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I want this variable to have a date format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached this dataset as a csv (semi colon separated values, actually) to the question.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 16:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400647#M278673</guid>
      <dc:creator>Autotelic</dc:creator>
      <dc:date>2017-10-03T16:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming two date and time variables in one DateTime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400661#M278674</link>
      <description>&lt;P&gt;DHMS() function in a query.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the date as the date component and the time as the second component and the others are zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dhms(date, 0, 0, time)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Oct 2017 17:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400661#M278674</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-03T17:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming two date and time variables in one DateTime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400674#M278675</link>
      <description>I get an error, it says the fourth parameter (time) must be numeric.</description>
      <pubDate>Tue, 03 Oct 2017 17:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400674#M278675</guid>
      <dc:creator>Autotelic</dc:creator>
      <dc:date>2017-10-03T17:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming two date and time variables in one DateTime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400675#M278676</link>
      <description>&lt;P&gt;Then convert time to a number using the INPUT() function.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 17:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400675#M278676</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-03T17:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming two date and time variables in one DateTime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400676#M278677</link>
      <description>&lt;P&gt;Then shouldn't it be what is below instead?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dhms(date, input(substr(time, 1, 2), 2.), input(substr(time, 4, 2), 2.), 0)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is this yields a number and I want some kind of date/datetime format.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 17:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400676#M278677</guid>
      <dc:creator>Autotelic</dc:creator>
      <dc:date>2017-10-03T17:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming two date and time variables in one DateTime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400677#M278678</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dhms(date, 0, 0, input(time, time.))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS stores date as a number, where its the number of days from Jan 1, 1960&lt;/P&gt;
&lt;P&gt;SAS stores datetime as numbers, where it is the number of seconds from Jan 1, 1960&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So yes, you get a number. And then you apply a datetime variable to view it as a datetime but it's still a number.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure if you're using SQL or a data step, but apply a format either way is easy.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	time="12:32";
	date='01Jan2017'd;
	my_date = dhms(date, 0, 0, input(time, time.));
	format my_date datetime21.;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Oct 2017 17:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400677#M278678</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-03T17:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming two date and time variables in one DateTime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400681#M278679</link>
      <description>&lt;P&gt;You can use the TIME informat to read the string directly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dhms(date,0,0,input(time,time.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the values to print in a way that meaningful then attach a format.&amp;nbsp; Like the datetime format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format datetime datetime19.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note there is a bug in the DATETIME format. Even though a 9 character date and an 8 character time plus a colon separator should fit in 18 characters SAS will use only two digits for the year if you use only 18 characters for the width in the format specification.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 17:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400681#M278679</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-03T17:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming two date and time variables in one DateTime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400685#M278680</link>
      <description>&lt;P&gt;Just a quick follow up question: what format should I use if time="20171003155533" and I want to get this in seconds?&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 18:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400685#M278680</guid>
      <dc:creator>Autotelic</dc:creator>
      <dc:date>2017-10-03T18:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming two date and time variables in one DateTime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400690#M278681</link>
      <description>&lt;P&gt;Is that supposed to be:&lt;/P&gt;
&lt;P&gt;October 3, 2017, 3:55.33?&lt;/P&gt;
&lt;P&gt;And is it a character variable or numeric?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would need to convert it to the correct number first in SAS and then apply the format.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 18:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400690#M278681</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-03T18:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming two date and time variables in one DateTime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400693#M278682</link>
      <description>&lt;P&gt;Yes, that's the time I'm going for, only it should be PM. It's a character variable. But what does the "correct number" mean here? Why is "20171003155533" incorrect?&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 18:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/400693#M278682</guid>
      <dc:creator>Autotelic</dc:creator>
      <dc:date>2017-10-03T18:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming two date and time variables in one DateTime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/401039#M278683</link>
      <description>&lt;P&gt;Because of what I said earlier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;SAS stores datetime as numbers, where it is the &lt;STRONG&gt;number of seconds from Jan 1, 1960&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your variable is a number that reflects a date but not something SAS can work from as a date. For example you can subtract SAS dates to determine the number of days between two dates. Numbers stored in the format you've shown will not allow for that type of calculation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The PM part comes from the format you apply to the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
mydate = "20171003155533";
mydate_num = input(mydate, best32.);
mydate_sas = input(mydate, B8601DJ.);
format mydate_num mydate_sas datetime.;
run;

proc print;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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 16:38:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-two-date-and-time-variables-in-one-DateTime/m-p/401039#M278683</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-04T16:38:37Z</dc:date>
    </item>
  </channel>
</rss>

