<?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 How to extract a date from a text in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-date-from-a-text/m-p/388996#M93268</link>
    <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to extract date from a text. Please suggest. Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data one;&lt;/P&gt;
&lt;P&gt;input text $;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;Today is friday (08aug2017) in Newyork&lt;/P&gt;
&lt;P&gt;Today (07Jun2017) is Monday in Texas&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;date&lt;/P&gt;
&lt;P&gt;2017-08-08&lt;/P&gt;
&lt;P&gt;2017-06-07&lt;/P&gt;</description>
    <pubDate>Thu, 17 Aug 2017 23:00:39 GMT</pubDate>
    <dc:creator>knveraraju91</dc:creator>
    <dc:date>2017-08-17T23:00:39Z</dc:date>
    <item>
      <title>How to extract a date from a text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-date-from-a-text/m-p/388996#M93268</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to extract date from a text. Please suggest. Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data one;&lt;/P&gt;
&lt;P&gt;input text $;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;Today is friday (08aug2017) in Newyork&lt;/P&gt;
&lt;P&gt;Today (07Jun2017) is Monday in Texas&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;date&lt;/P&gt;
&lt;P&gt;2017-08-08&lt;/P&gt;
&lt;P&gt;2017-06-07&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2017 23:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-date-from-a-text/m-p/388996#M93268</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2017-08-17T23:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a date from a text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-date-from-a-text/m-p/389004#M93272</link>
      <description>&lt;P&gt;If year is the only four digit number in the text field, then you could get away with something as simple as:&lt;/P&gt;
&lt;PRE&gt;data one;
  infile datalines truncover;
  format date yymmdd10.;
  input text $255.;
  date=input(substr(text,prxmatch('/\d\d\d\d/', text)-5,9),date9.);
  datalines;
123456789012345678901234
Today is friday (08aug2017) in Newyork
Today (07Jun2017) is Monday in Texas
;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2017 00:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-date-from-a-text/m-p/389004#M93272</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-08-18T00:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a date from a text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-date-from-a-text/m-p/389013#M93273</link>
      <description>&lt;P&gt;Is it always in brackets? For your example you could use SCAN but it depends on how&amp;nbsp;representative your sample is in comparison to your actual data.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2017 01:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-date-from-a-text/m-p/389013#M93273</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-18T01:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a date from a text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-date-from-a-text/m-p/389026#M93279</link>
      <description>&lt;P&gt;If the format is always ddmmmyyyy, try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input text $64.;
datalines;
Today is friday (08aug2017) in Newyork
Today (07Jun2017) is Monday in Texas
;

data two;
set one;
dPos = prxmatch ("/\d\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[12]\d\d\d/io",
    text); 
if dPos &amp;gt; 0 then date = input(substr(text,dPos,9),date9.);
format date yymmdd10.;
drop dPos;
run;

proc print noobs; run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Aug 2017 03:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-date-from-a-text/m-p/389026#M93279</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-08-18T03:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a date from a text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-date-from-a-text/m-p/389038#M93284</link>
      <description>&lt;P&gt;You can even write your own pattern-searching informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;

 invalue finddate (default=50)

 's/.*?             (?# lazy match of any character      )
    (               (?# 1st capture group                )
     \d{2}          (?# 2 digits [day]                   )
     \w{3}          (?# 3 letters [month]                )
     \d{4}          (?# 4 digits [year]                  )
    )               (?# close 1st capture group          )
    .*?             (?# lazy match of any character      )  
    /\1/x'         %*  keep date. type text   ;
                                               (regexpe)= [date9.] 

 other                                                  = .;

run;     
        
data _null_; 
  input X finddate.;
  putlog 'Date= ' X date9.  ; 
cards;
Today is friday (08aug2017) in Newyork
Today (07Jun2017) is Monday in Texas
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Date= 08AUG2017&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Date= 07JUN2017&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2017 04:38:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-date-from-a-text/m-p/389038#M93284</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-08-18T04:38:01Z</dc:date>
    </item>
  </channel>
</rss>

