<?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: How to extract seperate numeric date and time from Character datetime string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-seperate-numeric-date-and-time-from-Character/m-p/449401#M283589</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input datetime $50.;
datalines;
2008-01-03-09.58.19.207772
;
run;
data want (Drop=datetime_) ;
format datetime datetime24.3;
set have(rename=(datetime=datetime_));
datetime=dhms(input(substr(datetime_,1,10),yymmdd10.),0,0,input(substr(datetime_,12),time32.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need to rename the variable, if you wish to change the type of a variable as you desired. Rename and use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;suggestion to convert to DATETIME format&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Mar 2018 15:31:42 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2018-03-28T15:31:42Z</dc:date>
    <item>
      <title>How to extract seperate numeric date and time from Character datetime string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-seperate-numeric-date-and-time-from-Character/m-p/449355#M283586</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have character variables containing datetime stamps in the format of 0000-00-00-00.00.00.000000 (e.g. 2008-01-03-09.58.19.207772)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently able to extract the date part of these variables using the below code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;char_date = substr(char_&lt;FONT face="Courier New"&gt;date_time&lt;/FONT&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;num_date = input(&lt;FONT face="Courier New"&gt;char_date&lt;/FONT&gt;,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;anydtdte11.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; num_date_time2 &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;ddmmyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I now want to complete the same exercise in this step&amp;nbsp;to extract the time from these variables in to its own variable,&amp;nbsp;but after trying a number of things I can't seem to get it to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully someone can help. Thanks in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2018 14:46:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-seperate-numeric-date-and-time-from-Character/m-p/449355#M283586</guid>
      <dc:creator>paddy_fenna</dc:creator>
      <dc:date>2018-03-28T14:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract seperate numeric date and time from Character datetime string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-seperate-numeric-date-and-time-from-Character/m-p/449361#M283587</link>
      <description>&lt;P&gt;The same approach would work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you post what you've tried so far, so we can let you know where the mistake is?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/201637"&gt;@paddy_fenna&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have character variables containing datetime stamps in the format of 0000-00-00-00.00.00.000000 (e.g. 2008-01-03-09.58.19.207772)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am currently able to extract the date part of these variables using the below code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; want;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;char_date = substr(char_&lt;FONT face="Courier New"&gt;date_time&lt;/FONT&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;num_date = input(&lt;FONT face="Courier New"&gt;char_date&lt;/FONT&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;anydtdte11.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; num_date_time2 &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;ddmmyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I now want to complete the same exercise in this step&amp;nbsp;to extract the time from these variables in to its own variable,&amp;nbsp;but after trying a number of things I can't seem to get it to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hopefully someone can help. Thanks in advance.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2018 14:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-seperate-numeric-date-and-time-from-Character/m-p/449361#M283587</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-28T14:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract seperate numeric date and time from Character datetime string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-seperate-numeric-date-and-time-from-Character/m-p/449369#M283588</link>
      <description>&lt;P&gt;Should be easy.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input string $32. ;
  date = input(substr(string,1,10),yymmdd10.);
  time = input(substr(string,12),time32.);
  datetime=dhms(date,0,0,time);
  format datetime datetime24.3 date date9. time time12.3 ;
  put (_all_) (=/);
cards;
2008-01-03-09.58.19.207772
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;string=2008-01-03-09.58.19.207772
date=03JAN2008
time=9:58:19.208
datetime=03JAN2008:09:58:19.208
&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Mar 2018 14:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-seperate-numeric-date-and-time-from-Character/m-p/449369#M283588</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-28T14:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract seperate numeric date and time from Character datetime string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-seperate-numeric-date-and-time-from-Character/m-p/449401#M283589</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input datetime $50.;
datalines;
2008-01-03-09.58.19.207772
;
run;
data want (Drop=datetime_) ;
format datetime datetime24.3;
set have(rename=(datetime=datetime_));
datetime=dhms(input(substr(datetime_,1,10),yymmdd10.),0,0,input(substr(datetime_,12),time32.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need to rename the variable, if you wish to change the type of a variable as you desired. Rename and use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;suggestion to convert to DATETIME format&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2018 15:31:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-seperate-numeric-date-and-time-from-Character/m-p/449401#M283589</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-28T15:31:42Z</dc:date>
    </item>
  </channel>
</rss>

