<?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: Extracting Date and Time from a Character String when there are spaces in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Extracting-Date-and-Time-from-a-Character-String-when-there-are/m-p/310938#M8920</link>
    <description>&lt;P&gt;If you have SAS9.4, try anydtdtm.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input MemberNameNum     &amp;amp; $40.          DOB   &amp;amp; $40.  ServiceStart &amp;amp; $40.;
_dob=input(DOB,anydtdtm32.);
_start=input(ServiceStart,anydtdtm32.);
format _dob _start datetime.;
cards;
Prinze Jr,Freddie(124A)       Dec 21 1951 12:00AM          2014-07-31 00:00:00
Doe,John(100B)                   Apr 6 1955 12:00AM            2014-05-14 00:00:00
Abdul Jawad, Joe(325A)      Apr 21 1941 12:00AM          2015-07-29 00:00:00
;
run;
 proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 11 Nov 2016 12:19:29 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-11-11T12:19:29Z</dc:date>
    <item>
      <title>Extracting Date and Time from a Character String when there are spaces</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extracting-Date-and-Time-from-a-Character-String-when-there-are/m-p/310821#M8909</link>
      <description>&lt;P&gt;Hello all!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am having trouble extracting data and time from these variables (they are all character variables):&lt;BR /&gt;&lt;BR /&gt;MemberNameNum &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DOB &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; ServiceStart&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Prinze Jr,Freddie(124A) &amp;nbsp; &amp;nbsp; &amp;nbsp; Dec 21 1951 12:00AM &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2014-07-31 00:00:00&lt;/P&gt;
&lt;P&gt;Doe,John(100B) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Apr &amp;nbsp;6 1955 12:00AM &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2014-05-14 00:00:00&lt;/P&gt;
&lt;P&gt;Abdul Jawad, Joe(325A) &amp;nbsp; &amp;nbsp; &amp;nbsp;Apr 21 1941 12:00AM &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2015-07-29 00:00:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I would like to do is to get it in this format, where the dates and times are numeric SAS dates and times:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Last_name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;First_name &amp;nbsp; &amp;nbsp; &amp;nbsp;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DOB_date &amp;nbsp; &amp;nbsp; DOB_time &amp;nbsp; &amp;nbsp; Service_start_date &amp;nbsp; &amp;nbsp; &amp;nbsp;service_start_time&lt;/P&gt;
&lt;P&gt;Prinze Jr &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Freddie &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;124A &amp;nbsp; 12/21/1951 &amp;nbsp; 12:00AM &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07/31/2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;00:00:00&lt;/P&gt;
&lt;P&gt;Doe &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; John &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100B &amp;nbsp; &amp;nbsp;04/06/1955 &amp;nbsp; 12:00AM &amp;nbsp; &amp;nbsp; &amp;nbsp; 05/14/2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;00:00:00&lt;/P&gt;
&lt;P&gt;Abdul Jawad &amp;nbsp; &amp;nbsp; &amp;nbsp;Joe &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;325A &amp;nbsp; &amp;nbsp;04/21/1941 &amp;nbsp; &amp;nbsp;12:00AM &amp;nbsp; &amp;nbsp; &amp;nbsp;07/29/2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;00:00:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried playing around with the substring function but was havign trouble. You'll notice that there is no space after the comman in "last,first" but there is one in Joe's after the comma:"Abdul Jawad, Joe" and there is two spaces after April since the date, 6, only is one digit, but for everything else there is one space between the month and the day in&amp;nbsp;DOB. The times are all the same, but it would be nice to have them in case if someone's isn't 12:00AM or 00:00:00. I couldn't find the format for "Month day year" where month is abreviated and year is 4 digits (like what I have). I have been reading through the other postings to see if I could find a solution but alas, have not been able to solve this. Any help would be appreciated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Gina&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2016 23:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extracting-Date-and-Time-from-a-Character-String-when-there-are/m-p/310821#M8909</guid>
      <dc:creator>ginak</dc:creator>
      <dc:date>2016-11-10T23:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Date and Time from a Character String when there are spaces</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extracting-Date-and-Time-from-a-Character-String-when-there-are/m-p/310826#M8910</link>
      <description>&lt;P&gt;So we don't make a lot of assumptions and /or have to retype data please look here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; for instructions on how to turn your existing SAS data set into data set code that be pasted here or attached as a text file. Then we have something we can test on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: single field Names are one of the worst data contents to parse out, only exceeded by single field addresses in common data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LastName =scan(MemberNameNum,1,',');&lt;/P&gt;
&lt;P&gt;likely works for most. We may have to get more creative with the rest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please look at your data and see if the TIME part is ever other than 12:00AM for DOB or 00:00:00 for ServiceStart. If not then you do not actually have any time values to consider but are likely the victime of a lazy database designer that allows DATE values to ge stored as DATETIME without time values. Then the data looks like it actually has times but doesn't.&lt;/P&gt;
&lt;P&gt;The DOB may yield to:&lt;/P&gt;
&lt;P&gt;DobDate =&amp;nbsp;&amp;nbsp;input(&amp;nbsp; cats(scan(dob,2),scan(dob,1),scan(dob,3), date9.);&lt;/P&gt;
&lt;P&gt;format dobdate mmddyy10.&lt;/P&gt;
&lt;P&gt;Service_start_date = input(scan(servicestart,1,' '),yymmddD.);&lt;/P&gt;
&lt;P&gt;format Service_start_date mmddyy10.;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2016 23:27:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extracting-Date-and-Time-from-a-Character-String-when-there-are/m-p/310826#M8910</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-10T23:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Date and Time from a Character String when there are spaces</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extracting-Date-and-Time-from-a-Character-String-when-there-are/m-p/310938#M8920</link>
      <description>&lt;P&gt;If you have SAS9.4, try anydtdtm.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input MemberNameNum     &amp;amp; $40.          DOB   &amp;amp; $40.  ServiceStart &amp;amp; $40.;
_dob=input(DOB,anydtdtm32.);
_start=input(ServiceStart,anydtdtm32.);
format _dob _start datetime.;
cards;
Prinze Jr,Freddie(124A)       Dec 21 1951 12:00AM          2014-07-31 00:00:00
Doe,John(100B)                   Apr 6 1955 12:00AM            2014-05-14 00:00:00
Abdul Jawad, Joe(325A)      Apr 21 1941 12:00AM          2015-07-29 00:00:00
;
run;
 proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Nov 2016 12:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extracting-Date-and-Time-from-a-Character-String-when-there-are/m-p/310938#M8920</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-11T12:19:29Z</dc:date>
    </item>
  </channel>
</rss>

