<?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: Splitting a date/time string with no delimiter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537433#M147813</link>
    <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date = input(substr(string,1,8),yymmdd8.);
time = input(substr(string,9,6),time6.);
format
  date yymmddd10.
  time time8.
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 21 Feb 2019 15:30:27 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-02-21T15:30:27Z</dc:date>
    <item>
      <title>Splitting a date/time string with no delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537427#M147811</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have seen some posts about splitting text strings into multiple variables, including some date/time strings, but I have not found a solution that would work for my problem. I am importing device data that has multiple variables and one variable for date and time (called DATE_TIME). I need the string to be parsed out into date (formatted like 02/21/2019, so mmddyy10.) and time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An example of the string I am working with:&amp;nbsp;&lt;/P&gt;&lt;P&gt;20181002105310&amp;nbsp;&lt;/P&gt;&lt;P&gt;This would be 10/02/2018 at 10:53:10.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it is helpful - there are about 728 observations in this dataset, and I need to do this for two variables (DATE_TIME and TRANSMISSION_DATE_TIME) so it would be nice to be able to do this efficiently if possible &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 15:23:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537427#M147811</guid>
      <dc:creator>fordcr2</dc:creator>
      <dc:date>2019-02-21T15:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a date/time string with no delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537432#M147812</link>
      <description>&lt;P&gt;Input the string as a numeric SAS date/time value using the ANYDTDTM informat.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=leforinforref&amp;amp;docsetTarget=p1hsn1ji141r4zn0z3xm2dthop6a.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;https://documentation.sas.com/?docsetId=leforinforref&amp;amp;docsetTarget=p1hsn1ji141r4zn0z3xm2dthop6a.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An example is shown at that link.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From there, parsing out the date is done easily with the DATEPART function, parsing out the time is done easily with the TIMEPART function.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 15:31:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537432#M147812</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-21T15:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a date/time string with no delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537433#M147813</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date = input(substr(string,1,8),yymmdd8.);
time = input(substr(string,9,6),time6.);
format
  date yymmddd10.
  time time8.
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Feb 2019 15:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537433#M147813</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-21T15:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a date/time string with no delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537435#M147814</link>
      <description>&lt;P&gt;You will probably need to convert the data and time parts separately.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 str='20181002105310';
 date = input(str,yymmdd8.);
 time = input(substr(str,9),hhmmss6.);
 format date yymmdd10. time time8.;
 put (_all_) (=);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;str=20181002105310 date=2018-10-02 time=10:53:10
&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Feb 2019 15:30:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537435#M147814</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-21T15:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a date/time string with no delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537439#M147815</link>
      <description>&lt;P&gt;This works great! Do I need to make a macro so that the str variable will update?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ex) the first DATE_TIME is 20181002105310 which comes out to date: 2018-10-02 time: 10:53:10&lt;/P&gt;&lt;P&gt;the next DATE_TIME is 20170509073215 and I would need the same type of output for date and time, is there a way to make a loop where SAS will just read all of these DATE_TIME variables and convert them accordingly?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 15:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537439#M147815</guid>
      <dc:creator>fordcr2</dc:creator>
      <dc:date>2019-02-21T15:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a date/time string with no delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537459#M147821</link>
      <description>&lt;P&gt;A data step&amp;nbsp;&lt;EM&gt;is&lt;/EM&gt; a loop fed by input data (either from a dataset or from an external file).&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 16:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537459#M147821</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-21T16:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a date/time string with no delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537496#M147834</link>
      <description>&lt;P&gt;You're misunderstanding what I said. I was regarding the "str" variable for the string. Right now what that would do is autofill the same str variable for each DATE_TIME variable and subsequently each new output for date and time. I am asking how to make it so that a new str value will be produced for each DATE_TIME variable input.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 19:13:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537496#M147834</guid>
      <dc:creator>fordcr2</dc:creator>
      <dc:date>2019-02-21T19:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a date/time string with no delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537497#M147835</link>
      <description>&lt;P&gt;I figured it out using this code - thank you!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Changed it to:&lt;/P&gt;&lt;P&gt;Data PARI; set xml_files;&lt;BR /&gt;date = input(DATE_TIME,yymmdd8.);&lt;BR /&gt;time = input(substr(DATE_TIME,9),hhmmss6.);&lt;BR /&gt;format date mmddyy10. time time8.;&lt;BR /&gt;put (_all_) (=);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 19:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-date-time-string-with-no-delimiter/m-p/537497#M147835</guid>
      <dc:creator>fordcr2</dc:creator>
      <dc:date>2019-02-21T19:16:22Z</dc:date>
    </item>
  </channel>
</rss>

