<?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: Converting numeric date and time to SAS datetime22.3 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198744#M37253</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would just re-iterate, its best to keep data in SAS under SAS structure.&amp;nbsp; E.g. put times into time formats.&amp;nbsp; You can then change the display format of the underlying number, and perform other calculations quite easily.&amp;nbsp; Just makes working with it so much easier.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Jun 2015 14:11:41 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-06-03T14:11:41Z</dc:date>
    <item>
      <title>Converting numeric date and time to SAS datetime22.3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198738#M37247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having a lot of difficulty with converting a numerical date and time to a SAS datetime format.&lt;/P&gt;&lt;P&gt;In my data, I have two columns that represent the date and time numerically. I would like to convert and combine these into a new variable with a datetime22.3 format. below is an example of what my data looks like. The first two columns are the date and time, respectively (in numerical format). The third column (datetime22.3 format) is what I would like to create in a data step so that I can do date manipulations on it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="149" style="border: 1px solid #000000; width: 408px; height: 112px;" width="406"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;CreateDate&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;CreateTime&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;CreateDateTime&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;20140806&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;145749&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;06AUG2014:14:57:49.000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;20140805&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;164322&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;05AUG2014:16:43:22.000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;20140801&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;85631&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;01AUG2014:08:56:31.000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;20140801&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;85019&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;01AUG2014:08:50:19.000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;20140804&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;133422&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;04AUG2014:13:34:22.000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I know that one way to do this is to convert the date and time to string and put the "-" &amp;amp; ":" in, by means of a substr and concatenate functions. However, I want to know if there is a quick way do convert this directly in, say 2 or 3 steps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would appreciate the help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 09:43:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198738#M37247</guid>
      <dc:creator>GenDemo</dc:creator>
      <dc:date>2015-06-03T09:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric date and time to SAS datetime22.3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198739#M37248</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Personally, I think the biggest issue here is having the date and time as numeric, mostly the time variable.&amp;nbsp; The reason being is that time actually doesn't realy exist in this term, SAS stores the value as number of seconds from a certain point, in a numeric, whereas your numeric indicates the time.&amp;nbsp; Thus somehow you will need to interpret the numeric into the component parts and let SAS calculate seconds from to get a proper time value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; createdate=20140806; createtime=145749; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; createdate=20140805; createtime=164322; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; createdate=20140801; createtime=85631; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; inter=put(createtime,z6.);&amp;nbsp; /* In this instance I keep this part separate for clarity. */&lt;/P&gt;&lt;P&gt;&amp;nbsp; creationdatetime=dhms(input(put(createdate,8.),yymmdd8.),input(substr(inter,1,2),best.),input(substr(inter,3,2),best.),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input(substr(inter,5,2),best.));&lt;/P&gt;&lt;P&gt;&amp;nbsp; format creationdatetime datetime22.3;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 10:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198739#M37248</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-06-03T10:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric date and time to SAS datetime22.3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198740#M37249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;Hi,&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;I need to convert the format date "&lt;STRONG&gt;dd-mm-yyyy"&lt;/STRONG&gt; to format "&lt;STRONG&gt;dd-mm-yyyy hh:mm:ss"&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;which format should I use in sas campaign studio.&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;I would appreciate the help.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 11:35:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198740#M37249</guid>
      <dc:creator>Abenamor</dc:creator>
      <dc:date>2015-06-03T11:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric date and time to SAS datetime22.3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198741#M37250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You shouldn't jump anothers question.&amp;nbsp; As for your issue, I don't know campaign studio at all, however in base SAS you would do:&lt;/P&gt;&lt;P&gt;new_datetime_variable=dhms(date_variable,0,0,0);&lt;/P&gt;&lt;P&gt;Then format as you want from the list of formats available or create a user defined one:&lt;/P&gt;&lt;P&gt;&lt;A href="https://v8doc.sas.com/sashtml/lrcon/zenid-63.htm" title="https://v8doc.sas.com/sashtml/lrcon/zenid-63.htm"&gt;Dates, Times, and Intervals : SAS Date, Time, and Datetime Values&lt;/A&gt;&lt;/P&gt;&lt;P&gt;As you only have a date I have assumed 0 hours, 0 mins, 0 seconds for the time part which is required in a datetime format.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 12:02:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198741#M37250</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-06-03T12:02:40Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric date and time to SAS datetime22.3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198742#M37251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes please don't jump other people questions. &lt;/P&gt;&lt;P&gt;The thread becomes very difficult to read and the thread usually tends to go completely off topic and the question never gets answered - as happens in many other threads.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 13:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198742#M37251</guid>
      <dc:creator>GenDemo</dc:creator>
      <dc:date>2015-06-03T13:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric date and time to SAS datetime22.3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198743#M37252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much. &lt;/P&gt;&lt;P&gt;Your solution is not exactly what I was hoping for, but it is &lt;STRONG&gt;much&lt;/STRONG&gt; shorter than what I have. I appreciate your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just for interest, what I did:&lt;/P&gt;&lt;P&gt;data want2 (drop= time_str time_str2);&lt;/P&gt;&lt;P&gt; set have;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; /*Application Datetime*/&lt;/P&gt;&lt;P&gt; format createdate2 date9. createtime2 time8. creationdatetime datetime22.3;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; createdate2 = input(put(createdate,12.),b8601da.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; time_str= compress(input(put(createtime,12.),$12.));&lt;/P&gt;&lt;P&gt; if length(time_str) = 5 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; time_str2 = compress("0"||substr(time_str,1,1) ||":"|| substr(time_str,2,2) ||":"|| substr(time_str,4,2));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; createtime2 = input(put(time_str2,$8.),time8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; time_str2 = compress(substr(time_str,1,2) ||":"|| substr(time_str,3,2) ||":"|| substr(time_str,5,2));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; createtime2 = input(put(time_str2,$8.),time8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt; creationdatetime = input(compress(put(createdate2, date9.)||":"||put(createtime2, time.)),datetime22.3);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 13:51:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198743#M37252</guid>
      <dc:creator>GenDemo</dc:creator>
      <dc:date>2015-06-03T13:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric date and time to SAS datetime22.3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198744#M37253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would just re-iterate, its best to keep data in SAS under SAS structure.&amp;nbsp; E.g. put times into time formats.&amp;nbsp; You can then change the display format of the underlying number, and perform other calculations quite easily.&amp;nbsp; Just makes working with it so much easier.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 14:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-date-and-time-to-SAS-datetime22-3/m-p/198744#M37253</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-06-03T14:11:41Z</dc:date>
    </item>
  </channel>
</rss>

