<?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: Combine date and time columns into yyyy-mm-dd hh:mm:ss.ms in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-date-and-time-columns-into-yyyy-mm-dd-hh-mm-ss-ms/m-p/841114#M332566</link>
    <description>Great post, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; !&lt;BR /&gt;Thank you,&lt;BR /&gt;HHC</description>
    <pubDate>Thu, 27 Oct 2022 12:01:02 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2022-10-27T12:01:02Z</dc:date>
    <item>
      <title>Combine date and time columns into yyyy-mm-dd hh:mm:ss.ms</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-date-and-time-columns-into-yyyy-mm-dd-hh-mm-ss-ms/m-p/841059#M332550</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;My data has a date column and time column.&lt;/P&gt;
&lt;P&gt;I would like to create a column datetime with format&amp;nbsp;&lt;STRONG&gt;yyyy-mm-dd hh:mm:ss.ms&lt;/STRONG&gt; and export to csv.&lt;/P&gt;
&lt;P&gt;Clearly, my time doesn't has millisecond and 00000 is fine.&lt;/P&gt;
&lt;P&gt;Can you please help me to get the code?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date time;
informat time time11.;
format date date9. time time11.;
datalines;

20130730 4:00:00
20130130 5:15:00
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture mydt   (default=24)
low-high='%Y-%0m-%0d %0H:%0M:%0S.0000' (datatype=datetime)
;
run;

data have;
   input date time;
   informat date yymmdd10. time time11.;
   format date date9. time time11.;
datalines;
20130730 4:00:00
20130130 5:15:00
run;

data want; set have;
   dt = dhms(date,0,0,time);
   format dt mydt.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 11:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-date-and-time-columns-into-yyyy-mm-dd-hh-mm-ss-ms/m-p/841059#M332550</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-10-27T11:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: Combine date and time columns into yyyy-mm-dd hh:mm:ss.ms</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-date-and-time-columns-into-yyyy-mm-dd-hh-mm-ss-ms/m-p/841063#M332551</link>
      <description>&lt;P&gt;You do not have a date in your dataset. Did you miss the correct informat in your data step?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 05:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-date-and-time-columns-into-yyyy-mm-dd-hh-mm-ss-ms/m-p/841063#M332551</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-27T05:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Combine date and time columns into yyyy-mm-dd hh:mm:ss.ms</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-date-and-time-columns-into-yyyy-mm-dd-hh-mm-ss-ms/m-p/841068#M332553</link>
      <description>&lt;P&gt;See if this gets you started:&lt;/P&gt;
&lt;PRE&gt;proc format;
picture mydt   (default=23)
low-high='%Y-%0m-%0d %0H:%0M:%0S.000' (datatype=datetime)
;
run;

data have;
   input date time;
   informat date yymmdd10. time time11.;
   format date date9. time time11.;
   dt = dhms(date,0,0,time);
   format dt mydt.;
datalines;
20130730 4:00:00
20130130 5:15:00
run;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is going on: Read proc format documentation on the Picture statement. Your desired datetime appearance is kind of non-standard so you have to roll your own with proc format. The MYdt format will display any fractional seconds as .000 so if you actually have values to display good luck. The directives in the Picture statement, those things starting with % are case sensitive so &lt;STRONG&gt;read&lt;/STRONG&gt; the documentation. This is one of the few places that the quotes need to be single quotes around the string of directives. If you use double quotes you will get a bunch of errors from the macro language processor. The characters other than the %, directive letter and 0 in between are all displayed literally. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you have a choice between a 24 hour clock, used, and 12 hour. Also the choices shown place a 0 before some of the values when they would be less than 10, so you get 2022-08-03 for the date portion instead of 2022-8-3 and similar for the hour, minute and seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a similar format supplied by SAS, E8601DTw.d but it places a T between the date and time portions instead of a space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code also shows how to read shown values as the believed date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 06:25:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-date-and-time-columns-into-yyyy-mm-dd-hh-mm-ss-ms/m-p/841068#M332553</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-27T06:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Combine date and time columns into yyyy-mm-dd hh:mm:ss.ms</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-date-and-time-columns-into-yyyy-mm-dd-hh-mm-ss-ms/m-p/841114#M332566</link>
      <description>Great post, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; !&lt;BR /&gt;Thank you,&lt;BR /&gt;HHC</description>
      <pubDate>Thu, 27 Oct 2022 12:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-date-and-time-columns-into-yyyy-mm-dd-hh-mm-ss-ms/m-p/841114#M332566</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-10-27T12:01:02Z</dc:date>
    </item>
  </channel>
</rss>

