<?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: Separate date from time in a character column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Separate-date-from-time-in-a-character-column/m-p/438193#M109221</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
   length dtchar $20 ;
   input dtchar $20.;
cards;
05/02/2014 04:45:57
05/01/2014 06:00:00
05/01/2014 06:00:00
10/29/2014 20:05:00
;

data want;
set have;
_temp=input(dtchar,anydtdtm21.);
date=datepart(_temp);
time=timepart(_temp);
format date date9. time time10.;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 17 Feb 2018 20:41:03 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-02-17T20:41:03Z</dc:date>
    <item>
      <title>Separate date from time in a character column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-date-from-time-in-a-character-column/m-p/438188#M109218</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a character column with $20. format. This column contains date and time. I want to split the column into two columns with one columns containing only date and the other one only the time. Could anyone please help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample date:&lt;/P&gt;&lt;P&gt;Current format: $20.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date&lt;/P&gt;&lt;P&gt;05/02/2014 04:45:57&lt;/P&gt;&lt;P&gt;05/01/2014 06:00:00&lt;/P&gt;&lt;P&gt;05/01/2014 06:00:00&lt;/P&gt;&lt;P&gt;10/29/2014 20:05:00&lt;/P&gt;</description>
      <pubDate>Sat, 17 Feb 2018 20:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-date-from-time-in-a-character-column/m-p/438188#M109218</guid>
      <dc:creator>nazmul</dc:creator>
      <dc:date>2018-02-17T20:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: Separate date from time in a character column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-date-from-time-in-a-character-column/m-p/438191#M109219</link>
      <description>&lt;P&gt;one way to do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;time = input(scan(date,2, ' '),time8.);
format time time8.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Feb 2018 20:23:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-date-from-time-in-a-character-column/m-p/438191#M109219</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-02-17T20:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: Separate date from time in a character column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-date-from-time-in-a-character-column/m-p/438192#M109220</link>
      <description>&lt;P&gt;You can easily use SUBSTR() to pull apart the data if it as clean as your examples.&lt;/P&gt;
&lt;P&gt;Let's make some sample data out of your listing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
   length dtchar $20 ;
   input dtchar $20.;
cards;
05/02/2014 04:45:57
05/01/2014 06:00:00
05/01/2014 06:00:00
10/29/2014 20:05:00
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now to make new character variables use SUBSTR().&amp;nbsp; If you want you can convert them into actual date and time variables and even combine back together into a datetime variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  length datechar $10 timechar $8 ;
  datechar = substr(dtchar,1,10);
  timechar = substr(dtchar,12);
  date = input(datechar,mmddyy10.);
  time = input(timechar,time8.);
  dt = dhms(date,0,0,time);
  format date yymmdd10. time time8. dt datetime20. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;Obs          dtchar            datechar     timechar          date        time                      dt

 1     05/02/2014 04:45:57    05/02/2014    04:45:57    2014-05-02     4:45:57      02MAY2014:04:45:57
 2     05/01/2014 06:00:00    05/01/2014    06:00:00    2014-05-01     6:00:00      01MAY2014:06:00:00
 3     05/01/2014 06:00:00    05/01/2014    06:00:00    2014-05-01     6:00:00      01MAY2014:06:00:00
 4     10/29/2014 20:05:00    10/29/2014    20:05:00    2014-10-29    20:05:00      29OCT2014:20:05:00&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt; that it is not the &lt;STRONG&gt;FORMAT&lt;/STRONG&gt;&amp;nbsp;that matters for variable definitions.&amp;nbsp; What matters is what &lt;STRONG&gt;LENGTH&lt;/STRONG&gt; it is defined to hold. The format attached doesn't matter unless you set it shorter than the length, in which case you might be confused about the variables contents when it prints truncated values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Feb 2018 20:29:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-date-from-time-in-a-character-column/m-p/438192#M109220</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-17T20:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Separate date from time in a character column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-date-from-time-in-a-character-column/m-p/438193#M109221</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
   length dtchar $20 ;
   input dtchar $20.;
cards;
05/02/2014 04:45:57
05/01/2014 06:00:00
05/01/2014 06:00:00
10/29/2014 20:05:00
;

data want;
set have;
_temp=input(dtchar,anydtdtm21.);
date=datepart(_temp);
time=timepart(_temp);
format date date9. time time10.;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Feb 2018 20:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-date-from-time-in-a-character-column/m-p/438193#M109221</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-17T20:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Separate date from time in a character column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-date-from-time-in-a-character-column/m-p/438194#M109222</link>
      <description>Thank you everyone for your help. All of you codes work. I selected the most convenient one as the code used date and time functions</description>
      <pubDate>Sat, 17 Feb 2018 20:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-date-from-time-in-a-character-column/m-p/438194#M109222</guid>
      <dc:creator>nazmul</dc:creator>
      <dc:date>2018-02-17T20:49:15Z</dc:date>
    </item>
  </channel>
</rss>

