<?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: Format for imported datetime fields as mm/dd/yyyy hh:mm in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Format-for-imported-datetime-fields-as-mm-dd-yyyy-hh-mm/m-p/634777#M78016</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52727"&gt;@lizzy28&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to import a txt file with multiple datetime fields with the format mm/dd/yyyy hh:mm, for example, 3/16/2020 3:09. I was able to import the fields with DATETIME19. format. Is it possible to have the fields display the way they were in txt file and remain the date format so that I can calculate the hour/minute differences? That means I like to have the format&amp;nbsp;mm/dd/yyyy hh:mm in the imported SAS data file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;Lizi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Personally not a fan of the Microsoft date time display as you never are sure if it is two variables or one when extracted.&lt;/P&gt;
&lt;P&gt;If you really want to duplicate the Microsoft appearance then you need to create a custom format.&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
picture msdt
low-high ='%m/%d/%Y %h:%0M' (datatype=datetime)
;
run;

data example;
	x='16Mar2020:03:09'dt;
	put 'Datetime format ' x= datetime. +1 'MSDT format ' x= msdt.;
run;&lt;/PRE&gt;
&lt;P&gt;Caveats with the directives in the Picture appearance options: The quotes here MUST be single quotes, otherwise the directives get interpreted as macro calls. The case of the letters is important, note the %m is month and %M is minute. If you want leading 0 in month, day, hour or minute insert a zero between the % and the letter, upper and lower case Y determine number of digits in the Year. Other characters are literal characters inserted. So the slashes and a space need to be where you want.&lt;/P&gt;
&lt;P&gt;If you sometimes what seconds and others don't you will likely need to create different formats as not using leading zeroes in month, day and hour means that you can't use the typical format length indicator to truncate seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will need to make sure the format is available in every SAS session you want&amp;nbsp; to use this format.&lt;/P&gt;
&lt;P&gt;Personally I would stick with the SAS Datetime.&lt;/P&gt;</description>
    <pubDate>Wed, 25 Mar 2020 15:00:16 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-03-25T15:00:16Z</dc:date>
    <item>
      <title>Format for imported datetime fields as mm/dd/yyyy hh:mm</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Format-for-imported-datetime-fields-as-mm-dd-yyyy-hh-mm/m-p/634617#M77981</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to import a txt file with multiple datetime fields with the format mm/dd/yyyy hh:mm, for example, 3/16/2020 3:09. I was able to import the fields with DATETIME19. format. Is it possible to have the fields display the way they were in txt file and remain the date format so that I can calculate the hour/minute differences? That means I like to have the format&amp;nbsp;mm/dd/yyyy hh:mm in the imported SAS data file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;Lizi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 02:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Format-for-imported-datetime-fields-as-mm-dd-yyyy-hh-mm/m-p/634617#M77981</guid>
      <dc:creator>lizzy28</dc:creator>
      <dc:date>2020-03-25T02:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Format for imported datetime fields as mm/dd/yyyy hh:mm</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Format-for-imported-datetime-fields-as-mm-dd-yyyy-hh-mm/m-p/634623#M77982</link>
      <description>&lt;P&gt;If you can't find a suitable out-of-the box format then there is always the option to create your own picture format using a datetime directive.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Examples found &lt;A href="https://support.sas.com/techsup/notes/v8/8/510.html" target="_self"&gt;here&lt;/A&gt; which already create almost what you're asking for.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One needs simply to remove the directive for seconds and things should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
 picture dttime other='%0m/%0d/%0y %0H:%0M'
 (datatype=datetime);
run;
data test;
  dttm=datetime();
  format dttm dttime.;
run;
proc print data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Please note: The format will not round to minutes but just display complete minutes. 4 minutes 59 seconds will display as 4 minutes.&lt;/P&gt;
&lt;P&gt;The internal SAS Date value remains unchanged (=count of seconds since 1/1/1960) and calculations will use the exact values.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 04:47:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Format-for-imported-datetime-fields-as-mm-dd-yyyy-hh-mm/m-p/634623#M77982</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-25T04:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: Format for imported datetime fields as mm/dd/yyyy hh:mm</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Format-for-imported-datetime-fields-as-mm-dd-yyyy-hh-mm/m-p/634777#M78016</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52727"&gt;@lizzy28&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to import a txt file with multiple datetime fields with the format mm/dd/yyyy hh:mm, for example, 3/16/2020 3:09. I was able to import the fields with DATETIME19. format. Is it possible to have the fields display the way they were in txt file and remain the date format so that I can calculate the hour/minute differences? That means I like to have the format&amp;nbsp;mm/dd/yyyy hh:mm in the imported SAS data file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;Lizi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Personally not a fan of the Microsoft date time display as you never are sure if it is two variables or one when extracted.&lt;/P&gt;
&lt;P&gt;If you really want to duplicate the Microsoft appearance then you need to create a custom format.&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
picture msdt
low-high ='%m/%d/%Y %h:%0M' (datatype=datetime)
;
run;

data example;
	x='16Mar2020:03:09'dt;
	put 'Datetime format ' x= datetime. +1 'MSDT format ' x= msdt.;
run;&lt;/PRE&gt;
&lt;P&gt;Caveats with the directives in the Picture appearance options: The quotes here MUST be single quotes, otherwise the directives get interpreted as macro calls. The case of the letters is important, note the %m is month and %M is minute. If you want leading 0 in month, day, hour or minute insert a zero between the % and the letter, upper and lower case Y determine number of digits in the Year. Other characters are literal characters inserted. So the slashes and a space need to be where you want.&lt;/P&gt;
&lt;P&gt;If you sometimes what seconds and others don't you will likely need to create different formats as not using leading zeroes in month, day and hour means that you can't use the typical format length indicator to truncate seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will need to make sure the format is available in every SAS session you want&amp;nbsp; to use this format.&lt;/P&gt;
&lt;P&gt;Personally I would stick with the SAS Datetime.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 15:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Format-for-imported-datetime-fields-as-mm-dd-yyyy-hh-mm/m-p/634777#M78016</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-25T15:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Format for imported datetime fields as mm/dd/yyyy hh:mm</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Format-for-imported-datetime-fields-as-mm-dd-yyyy-hh-mm/m-p/634778#M78017</link>
      <description>Why would you want to use MDY order for the parts of date?  That will result in strings that are ambiguous.  Does '10/12/2019'  mean October twelfth or tenth of December?</description>
      <pubDate>Wed, 25 Mar 2020 15:05:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Format-for-imported-datetime-fields-as-mm-dd-yyyy-hh-mm/m-p/634778#M78017</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-25T15:05:57Z</dc:date>
    </item>
    <item>
      <title>Re: Format for imported datetime fields as mm/dd/yyyy hh:mm</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Format-for-imported-datetime-fields-as-mm-dd-yyyy-hh-mm/m-p/634807#M78025</link>
      <description>It's more personal preference &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 25 Mar 2020 16:16:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Format-for-imported-datetime-fields-as-mm-dd-yyyy-hh-mm/m-p/634807#M78025</guid>
      <dc:creator>lizzy28</dc:creator>
      <dc:date>2020-03-25T16:16:51Z</dc:date>
    </item>
  </channel>
</rss>

