<?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: Extract a date from a text string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-a-date-from-a-text-string/m-p/773742#M245842</link>
    <description>&lt;P&gt;This is a non-prx way to get to some of this. Doesn't handle all cases as shown but easy enough to add conditions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	orig='HAS COMPLETED THE TRIAL. DATE OF LAST SCAN SHOWING STABLE DISEASE- 30/10/2020';
	output;
	orig='TRIAL COMPLETED. LAST CT SCAN SHOWING STABLE DISEASE WAS 05/NOV/2020';
	output;
	orig='COMPLETION OF 2 YEARS TREATMENT- CT 21/04/21 SHOWS STABLE DISEASE';
	output;
run;

data want;
	set have;
	length found_date $20.;
	retain date found_date;
	date=.;
	found_date='';
	format date date9.;

	do i=1 to countw(orig);
		word=scan(orig, i, " ");

		if find(word, "/")&amp;gt;0 then
			do;
				date=input(word, anydtdte.);
				found_date=word;
			end;
	end;
	drop i word;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/59697"&gt;@jenim514&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need some suggestions on how I can extract a date in&amp;nbsp; nn/nn/yyyy format.&amp;nbsp; I use 'nn' rather than mm/dd because the data is entered in such a way where sometimes its mm/dd/yyyy or dd/mm/yyyy etc...&amp;nbsp; but date always presents in some format using back slashes.&amp;nbsp; I think prx may be the only was to do this, but I'm not familiar with it at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;'HAS COMPLETED THE TRIAL. DATE OF LAST SCAN SHOWING STABLE DISEASE- 30/10/2020'&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;TRIAL COMPLETED. LAST CT SCAN SHOWING STABLE DISEASE WAS 05/NOV/2020&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;COMPLETION OF 2 YEARS TREATMENT- CT 21/04/21 SHOWS STABLE DISEASE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found this code that searches for dates embeded in text, and it worked great, but only output '1' ...for yes a date exisits.&amp;nbsp; I feel like it could be modified to output an actual date to a new variablee, but not sure where to start there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is greatly appreciated!!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; date_search =
prxparse("m*january|february|march|april|june|july|august|september|october
|november|december|jan\.|feb\.|mar\.|apr\.|may\.|jun\.|jul\.|aug\.|sep\.|oc
t\.|nov\.|dec\.|, 19|, 20|\d-
|\djan|\dfeb|\dmar|\dapr|\dmay|\djun|\djul|\daug|\dsep|\doct|\dnov|\ddec|ja
n,|feb,|mar,|apr,|may,|jun,|jul,|aug,|sep,|oct,|nov,|dec,|jan \d|feb \d|mar
\d|apr \d|may \d|jun \d|jul \d|aug \d|sep \d|oct \d|nov \d|dec 


\d|jan\d|feb\d|mar\d|apr\d|may\d|jun\d|jul\d|aug\d|sep\d|oct\d|nov\d|dec\d|
\d/|\d\d \d\d \d\d|\d:\d|\d\.\d\d\.\d|\d\.\d\.\d|jan-|feb-|mar-|apr-|may-
|jun-|jul-|aug-|sep-|oct-|nov-|dec-*oi");
 if prxmatch(date_search,EOTDTHR )&amp;gt;0 then output;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Oct 2021 19:57:13 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-10-12T19:57:13Z</dc:date>
    <item>
      <title>Extract a date from a text string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-a-date-from-a-text-string/m-p/773738#M245840</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need some suggestions on how I can extract a date in&amp;nbsp; nn/nn/yyyy format.&amp;nbsp; I use 'nn' rather than mm/dd because the data is entered in such a way where sometimes its mm/dd/yyyy or dd/mm/yyyy etc...&amp;nbsp; but date always presents in some format using back slashes.&amp;nbsp; I think prx may be the only was to do this, but I'm not familiar with it at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;'HAS COMPLETED THE TRIAL. DATE OF LAST SCAN SHOWING STABLE DISEASE- 30/10/2020'&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;TRIAL COMPLETED. LAST CT SCAN SHOWING STABLE DISEASE WAS 05/NOV/2020&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;COMPLETION OF 2 YEARS TREATMENT- CT 21/04/21 SHOWS STABLE DISEASE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found this code that searches for dates embeded in text, and it worked great, but only output '1' ...for yes a date exisits.&amp;nbsp; I feel like it could be modified to output an actual date to a new variablee, but not sure where to start there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is greatly appreciated!!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; date_search =
prxparse("m*january|february|march|april|june|july|august|september|october
|november|december|jan\.|feb\.|mar\.|apr\.|may\.|jun\.|jul\.|aug\.|sep\.|oc
t\.|nov\.|dec\.|, 19|, 20|\d-
|\djan|\dfeb|\dmar|\dapr|\dmay|\djun|\djul|\daug|\dsep|\doct|\dnov|\ddec|ja
n,|feb,|mar,|apr,|may,|jun,|jul,|aug,|sep,|oct,|nov,|dec,|jan \d|feb \d|mar
\d|apr \d|may \d|jun \d|jul \d|aug \d|sep \d|oct \d|nov \d|dec 


\d|jan\d|feb\d|mar\d|apr\d|may\d|jun\d|jul\d|aug\d|sep\d|oct\d|nov\d|dec\d|
\d/|\d\d \d\d \d\d|\d:\d|\d\.\d\d\.\d|\d\.\d\.\d|jan-|feb-|mar-|apr-|may-
|jun-|jul-|aug-|sep-|oct-|nov-|dec-*oi");
 if prxmatch(date_search,EOTDTHR )&amp;gt;0 then output;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 19:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-a-date-from-a-text-string/m-p/773738#M245840</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2021-10-12T19:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a date from a text string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-a-date-from-a-text-string/m-p/773742#M245842</link>
      <description>&lt;P&gt;This is a non-prx way to get to some of this. Doesn't handle all cases as shown but easy enough to add conditions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	orig='HAS COMPLETED THE TRIAL. DATE OF LAST SCAN SHOWING STABLE DISEASE- 30/10/2020';
	output;
	orig='TRIAL COMPLETED. LAST CT SCAN SHOWING STABLE DISEASE WAS 05/NOV/2020';
	output;
	orig='COMPLETION OF 2 YEARS TREATMENT- CT 21/04/21 SHOWS STABLE DISEASE';
	output;
run;

data want;
	set have;
	length found_date $20.;
	retain date found_date;
	date=.;
	found_date='';
	format date date9.;

	do i=1 to countw(orig);
		word=scan(orig, i, " ");

		if find(word, "/")&amp;gt;0 then
			do;
				date=input(word, anydtdte.);
				found_date=word;
			end;
	end;
	drop i word;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/59697"&gt;@jenim514&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need some suggestions on how I can extract a date in&amp;nbsp; nn/nn/yyyy format.&amp;nbsp; I use 'nn' rather than mm/dd because the data is entered in such a way where sometimes its mm/dd/yyyy or dd/mm/yyyy etc...&amp;nbsp; but date always presents in some format using back slashes.&amp;nbsp; I think prx may be the only was to do this, but I'm not familiar with it at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;'HAS COMPLETED THE TRIAL. DATE OF LAST SCAN SHOWING STABLE DISEASE- 30/10/2020'&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;TRIAL COMPLETED. LAST CT SCAN SHOWING STABLE DISEASE WAS 05/NOV/2020&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;COMPLETION OF 2 YEARS TREATMENT- CT 21/04/21 SHOWS STABLE DISEASE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found this code that searches for dates embeded in text, and it worked great, but only output '1' ...for yes a date exisits.&amp;nbsp; I feel like it could be modified to output an actual date to a new variablee, but not sure where to start there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is greatly appreciated!!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; date_search =
prxparse("m*january|february|march|april|june|july|august|september|october
|november|december|jan\.|feb\.|mar\.|apr\.|may\.|jun\.|jul\.|aug\.|sep\.|oc
t\.|nov\.|dec\.|, 19|, 20|\d-
|\djan|\dfeb|\dmar|\dapr|\dmay|\djun|\djul|\daug|\dsep|\doct|\dnov|\ddec|ja
n,|feb,|mar,|apr,|may,|jun,|jul,|aug,|sep,|oct,|nov,|dec,|jan \d|feb \d|mar
\d|apr \d|may \d|jun \d|jul \d|aug \d|sep \d|oct \d|nov \d|dec 


\d|jan\d|feb\d|mar\d|apr\d|may\d|jun\d|jul\d|aug\d|sep\d|oct\d|nov\d|dec\d|
\d/|\d\d \d\d \d\d|\d:\d|\d\.\d\d\.\d|\d\.\d\.\d|jan-|feb-|mar-|apr-|may-
|jun-|jul-|aug-|sep-|oct-|nov-|dec-*oi");
 if prxmatch(date_search,EOTDTHR )&amp;gt;0 then output;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 19:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-a-date-from-a-text-string/m-p/773742#M245842</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-12T19:57:13Z</dc:date>
    </item>
  </channel>
</rss>

