<?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: Convert text to timestamp in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297439#M62460</link>
    <description>&lt;P&gt;One issue is that "01SEP2016" is not in the same format as &lt;CODE&gt;"&lt;/CODE&gt;&lt;CODE class="  language-sas"&gt;yymmdd10&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;/CODE&gt;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to run it like so, and it works:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.datetimes2   ;
    excel_datetime="01SEP2016:18:11:34"dt;
    excel_millis = 54;
    
    datetime = compress(put(excel_datetime,datetime27.)||"."||put(excel_millis,z3.) );
    
    datetime2 = input(datetime, datetime23.3);
    
    format datetime2 datetime23.3;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Sep 2016 15:54:38 GMT</pubDate>
    <dc:creator>paulkaefer</dc:creator>
    <dc:date>2016-09-09T15:54:38Z</dc:date>
    <item>
      <title>Convert text to timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297395#M62432</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;i need to convert a column&amp;nbsp;&lt;CODE class=" language-sas"&gt;TM_INS_C &amp;nbsp;&lt;/CODE&gt;char ($26.) "2016-09-05-17.38.51.717187"&amp;nbsp;to timestamp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I use thsi query:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORKUSI.T03_totale_pag_P ;
set WORKUSI.T03_totale_pag;
new_var=input(TM_INS_C,datetime26.);
FORMAT new_var datetime26.;
WHERE NDG_TITR_CARTA = '034361749';
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but i have this error:&lt;/P&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;NOTE: Invalid argument to function INPUT at line 1723 column 13.
TM_INS_C=2016-07-25-17.03.46.213975 CO_CAU_OPER_ATM=M90 CO_SUB_CAU_OPE_ATM=0000
NDG_TITR_CARTA=034361749 CO_KEY_CARTA_ATM=20081436919871987 DT_OPE=25JUL2016
OR_OPE=17:03:00 DB_OPER=PAGAMENTO BOLLETTINI POST IM_OPER_ATM=0.000 FL_CARTA_BANCA=S
FL_CARTA_POOL=N CODCAB=03045 CO_ATM=05496 TIPOPER_=M900000 KEYATM=020080304505496
CONTO=PAGAMENTI DESCR=PAGAMENTO BOLLETTINI POST LOG=PAGAMENTI new_var=. _ERROR_=1 _N_=11
NOTE: Mathematical operations could not be performed at the following places. The results
      of the operations have been set to missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      11 at 1723:13
NOTE: There were 11 observations read from the data set WORKUSI.T03_TOTALE_PAG.
      WHERE NDG_TITR_CARTA='034361749';
NOTE: The data set WORKUSI.T03_TOTALE_PAG_P has 11 observations and 19 variables.
NOTE: DATA statement used (Total process time):
      real time           1.49 seconds
      cpu time            0.12 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is my error ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank's&lt;/P&gt;
&lt;P&gt;M.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 13:42:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297395#M62432</guid>
      <dc:creator>Cello23</dc:creator>
      <dc:date>2016-09-09T13:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297401#M62436</link>
      <description>&lt;P&gt;Is&amp;nbsp;&lt;SPAN&gt;"2016-09-05-17.38.51.717187" valid input to the&amp;nbsp;datetime26. informat?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000199624.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000199624.htm&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 14:03:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297401#M62436</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2016-09-09T14:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297402#M62437</link>
      <description>&lt;P&gt;As &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15043"&gt;@ScottBass&lt;/a&gt; mentions, the variable as-is does not work properly. So what I would do is parse the string for dates and times, and combine them with the &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000179419.htm" target="_self"&gt;DHMS function&lt;/A&gt;. This worked for me:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.timestamps;
    TM_INS_C = "2016-09-05-17.38.51.717187";

    date = input(substr(TM_INS_C, 1, 10), yymmdd10.);
    time = input(substr(TM_INS_C, 12, 10), time10.);
    date_time = dhms(date, 0, 0, time);

    format date yymmdd10.
           time time10.
           date_time datetime.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Sep 2016 14:13:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297402#M62437</guid>
      <dc:creator>paulkaefer</dc:creator>
      <dc:date>2016-09-09T14:13:30Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297408#M62442</link>
      <description>Thank's!!!! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 09 Sep 2016 14:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297408#M62442</guid>
      <dc:creator>Cello23</dc:creator>
      <dc:date>2016-09-09T14:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297423#M62449</link>
      <description>&lt;P&gt;Sorry ... another similar question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two column:&lt;/P&gt;
&lt;P&gt;excel_datetime (DATETIME27.) , example (&amp;nbsp;01SEP2016:18:11:34)&lt;/P&gt;
&lt;P&gt;excel_millis (BEST12.), example (54)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i need this final result:&amp;nbsp;&lt;SPAN&gt;01SEP2016:18:11:34.054 (datetime23.3).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;My query is:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORKUSI.T02_ope_bar_p   ;
set  workusi.T02_ope_bar;
   	
datetime = compress(put(excel_datetime,datetime27.)||"."||put(excel_millis,z3.) );
 
date = input(substr(datetime, 1, 10), yymmdd10.);
time = input(substr(datetime, 12, 10), time10.);
date_time_new = dhms(date, 0, 0, time);
where atm_nr=3542;
 
    format date yymmdd10.
           time time10.
           date_time datetime23.3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;what's my error ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;thank's&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 15:32:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297423#M62449</guid>
      <dc:creator>Cello23</dc:creator>
      <dc:date>2016-09-09T15:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297432#M62456</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/3081"&gt;@Cello23&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Sorry ... another similar question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two column:&lt;/P&gt;&lt;P&gt;excel_datetime (DATETIME27.) , example (&amp;nbsp;01SEP2016:18:11:34)&lt;/P&gt;&lt;P&gt;excel_millis (BEST12.), example (54)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i need this final result:&amp;nbsp;&lt;SPAN&gt;01SEP2016:18:11:34.054 (datetime23.3).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My query is:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORKUSI.T02_ope_bar_p   ;
set  workusi.T02_ope_bar;
   	
datetime = compress(put(excel_datetime,datetime27.)||"."||put(excel_millis,z3.) );
 
date = input(substr(datetime, 1, 10), yymmdd10.);
time = input(substr(datetime, 12, 10), time10.);
date_time_new = dhms(date, 0, 0, time);
where atm_nr=3542;
 
    format date yymmdd10.
           time time10.
           date_time datetime23.3;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;what's my error ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thank's&lt;/SPAN&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If&amp;nbsp;&lt;/P&gt;&lt;P&gt;excel_datetime (DATETIME27.) really is the text '01SEP2016:18:11:34', and excel_millis really is the text '54', then consider:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;datetime=input(excel_datetime,datetime27.); &amp;nbsp;* that text is a valid SAS datetime literal ;&lt;/P&gt;&lt;P&gt;millis=input(excel_millis,best.)/1000; &amp;nbsp;* stored as the number of milliseconds.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;datetime=datetime+millis; &amp;nbsp;* add the fractional seconds to the datetime ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TBH, I'm not sure if adding the fractional seconds to the datetime yields the correct result, and I don't have SAS in front of me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I do know you don't have to jump through hoops parsing the datetime string; it already works as a SAS datetime literal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTH...&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 15:45:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297432#M62456</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2016-09-09T15:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297438#M62459</link>
      <description>&lt;P&gt;Sorry, I mis-read your post...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data WORKUSI.T02_ope_bar_p   ;
set  workusi.T02_ope_bar;
   	
datetime = compress(put(excel_datetime,datetime27.)||"."||put(excel_millis,z3.) );
 
date = input(substr(datetime, 1, 10), yymmdd10.);
time = input(substr(datetime, 12, 10), time10.);
date_time_new = dhms(date, 0, 0, time);
where atm_nr=3542;
 
    format date yymmdd10.
           time time10.
           date_time datetime23.3;
run;&lt;/PRE&gt;&lt;P&gt;So, excel_datetime is *already* a datetime value, and you're using the datetime27. format to convert it to text.&lt;/P&gt;&lt;P&gt;And excel_millis is *already* a numeric value, and you're using the z3. format to convert it to text.&lt;/P&gt;&lt;P&gt;Then you're concatenating them with a period.&lt;/P&gt;&lt;P&gt;Then parsing the concatenated string back into a date and time string, using the yymmdd10. and time10. informats to convert back to a date and time value.&lt;/P&gt;&lt;P&gt;Then using the DHMS function to convert the separate date and time values into a datetime value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whew!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you already have a datetime value, and a numeric value for milliseconds, I think you should just be able to add them together??? &amp;nbsp;You just need the offset required to get the right result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry, I don't have SAS in front of me, but if you generate the expected output, look at the numeric number generated, and compare your source data, you should be able to work it out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If not, then sure, convert to text, but I don't think you have to parse it back again. &amp;nbsp;Something like this should work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;datetime = input('12SEP2016:12.34.56.054',datetime27.3); &amp;nbsp;* or whatever the w.d values should be ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTH...&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 15:57:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297438#M62459</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2016-09-09T15:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297439#M62460</link>
      <description>&lt;P&gt;One issue is that "01SEP2016" is not in the same format as &lt;CODE&gt;"&lt;/CODE&gt;&lt;CODE class="  language-sas"&gt;yymmdd10&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;/CODE&gt;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to run it like so, and it works:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.datetimes2   ;
    excel_datetime="01SEP2016:18:11:34"dt;
    excel_millis = 54;
    
    datetime = compress(put(excel_datetime,datetime27.)||"."||put(excel_millis,z3.) );
    
    datetime2 = input(datetime, datetime23.3);
    
    format datetime2 datetime23.3;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 15:54:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297439#M62460</guid>
      <dc:creator>paulkaefer</dc:creator>
      <dc:date>2016-09-09T15:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297441#M62462</link>
      <description>&lt;P&gt;01SEP2016 is in date9. format&lt;/P&gt;&lt;P&gt;18:11:34 is in time8. format&lt;/P&gt;&lt;P&gt;01SEP2016:18:11:34 is in datetime&amp;lt;w&amp;gt; format&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hit the doc on SAS formats and informats. &amp;nbsp;For dates, review the section where they're grouped by category.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(I had to support code once where it always had compress(put(date,yymmdd10.),'-'). &amp;nbsp;Why didn't they just code put(date,yymmddn8.)? &amp;nbsp; Get familiar with all the formats and informats available, and where to quickly find them (I can never remember them all!) &amp;nbsp;This will serve you in good stead in your SAS coding career!)&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 16:07:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-timestamp/m-p/297441#M62462</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2016-09-09T16:07:07Z</dc:date>
    </item>
  </channel>
</rss>

