<?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 Is proc fcmp compatible with regular expressions? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Is-proc-fcmp-compatible-with-regular-expressions/m-p/579352#M75583</link>
    <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to adapt the date conversion function [1] to use regular expressions:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.functions.conversions; /*[1]*/
	function datecdash2sdtm(indate $) $; /*[2]*/
		length outdate $10; /*[3]*/
		cdash_date_regex = prxparse("/(UN|\d{1,2}) (\w{3}) (\d{4})/");

/*		if indate ne ' ' then*/
		if prxmatch(cdash_date_regex, indate) then
			do;
				yyyy = prxposn(cdash_date_regex, 3, indate);
				mmm = prxposn(cdash_date_regex, 2, indate);
				dd = prxposn(cdash_date_regex, 1, indate);
				/*yyyy = substr(indate, 8, 4); *//*[4]*/
/*				mmm = upcase(substr(indate, 4, 3));*/
/*				dd = substr(indate, 1, 2);*/

				/* if year not missing */
				if notdigit(yyyy) = 0 then
					do;
						/*[5]*/
						mm = put(mmm, $month.); /*[6]*/

						/* if month not missing */
						if mm ne ' ' then
							do;
								/* if day not missing */
								if notdigit(dd) = 0 then
									do;
										/*[5]*/
										outdate = yyyy || '-' || strip(mm) || '-' || dd; /*[7]*/
									end; /* if notdigit(dd) = 0 */
								else outdate = yyyy || '-' || strip(mm);
							end; /* if mm ne ' ' */
						else outdate = yyyy;
					end; /* if notdigit(yyyy) = 0 */
				else outdate = ' ';
			end; /* if indate ne ' ' */
		else outdate = ' ';
		return(outdate); /*[8]*/
	endsub; /*[9]*/
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Unfortunately the function is not working and produces empty output. If I try to just parse the dates in plain data step&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mh_crf;
	set ecrf.mh1b ecrf.mh1a;
	MHSTDTC = datecdash2sdtm(MHTRSTDAT);
	MHENDTC = datecdash2sdtm(MHTRENDAT);
	cdash_date_regex = prxparse("/(UN|\d{1,2}) (\w{3}) (\d{4})/");

	if prxmatch(cdash_date_regex, MHTRENDAT) then
		do;
			yyyy = prxposn(cdash_date_regex, 3, MHTRENDAT);
			mmm = prxposn(cdash_date_regex, 2, MHTRENDAT);
			dd = prxposn(cdash_date_regex, 1, MHTRENDAT);
		end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;then yyyy, mmm and dd variables are populated as expected. Are there any particular things one needs to keep in mind when mixing proc fcmp with regular expressions? Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[1]&amp;nbsp;&lt;A href="https://www.lexjansen.com/pharmasug/2017/TT/PharmaSUG-2017-TT07.pdf" target="_blank"&gt;https://www.lexjansen.com/pharmasug/2017/TT/PharmaSUG-2017-TT07.pdf&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Aug 2019 13:04:27 GMT</pubDate>
    <dc:creator>js5</dc:creator>
    <dc:date>2019-08-06T13:04:27Z</dc:date>
    <item>
      <title>Is proc fcmp compatible with regular expressions?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-proc-fcmp-compatible-with-regular-expressions/m-p/579352#M75583</link>
      <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to adapt the date conversion function [1] to use regular expressions:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.functions.conversions; /*[1]*/
	function datecdash2sdtm(indate $) $; /*[2]*/
		length outdate $10; /*[3]*/
		cdash_date_regex = prxparse("/(UN|\d{1,2}) (\w{3}) (\d{4})/");

/*		if indate ne ' ' then*/
		if prxmatch(cdash_date_regex, indate) then
			do;
				yyyy = prxposn(cdash_date_regex, 3, indate);
				mmm = prxposn(cdash_date_regex, 2, indate);
				dd = prxposn(cdash_date_regex, 1, indate);
				/*yyyy = substr(indate, 8, 4); *//*[4]*/
/*				mmm = upcase(substr(indate, 4, 3));*/
/*				dd = substr(indate, 1, 2);*/

				/* if year not missing */
				if notdigit(yyyy) = 0 then
					do;
						/*[5]*/
						mm = put(mmm, $month.); /*[6]*/

						/* if month not missing */
						if mm ne ' ' then
							do;
								/* if day not missing */
								if notdigit(dd) = 0 then
									do;
										/*[5]*/
										outdate = yyyy || '-' || strip(mm) || '-' || dd; /*[7]*/
									end; /* if notdigit(dd) = 0 */
								else outdate = yyyy || '-' || strip(mm);
							end; /* if mm ne ' ' */
						else outdate = yyyy;
					end; /* if notdigit(yyyy) = 0 */
				else outdate = ' ';
			end; /* if indate ne ' ' */
		else outdate = ' ';
		return(outdate); /*[8]*/
	endsub; /*[9]*/
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Unfortunately the function is not working and produces empty output. If I try to just parse the dates in plain data step&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mh_crf;
	set ecrf.mh1b ecrf.mh1a;
	MHSTDTC = datecdash2sdtm(MHTRSTDAT);
	MHENDTC = datecdash2sdtm(MHTRENDAT);
	cdash_date_regex = prxparse("/(UN|\d{1,2}) (\w{3}) (\d{4})/");

	if prxmatch(cdash_date_regex, MHTRENDAT) then
		do;
			yyyy = prxposn(cdash_date_regex, 3, MHTRENDAT);
			mmm = prxposn(cdash_date_regex, 2, MHTRENDAT);
			dd = prxposn(cdash_date_regex, 1, MHTRENDAT);
		end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;then yyyy, mmm and dd variables are populated as expected. Are there any particular things one needs to keep in mind when mixing proc fcmp with regular expressions? Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[1]&amp;nbsp;&lt;A href="https://www.lexjansen.com/pharmasug/2017/TT/PharmaSUG-2017-TT07.pdf" target="_blank"&gt;https://www.lexjansen.com/pharmasug/2017/TT/PharmaSUG-2017-TT07.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 13:04:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-proc-fcmp-compatible-with-regular-expressions/m-p/579352#M75583</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2019-08-06T13:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: Is proc fcmp compatible with regular expressions?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-proc-fcmp-compatible-with-regular-expressions/m-p/579368#M75584</link>
      <description>&lt;P&gt;It turns out that spaces were causing notdigit conditions to no longer be satisfied. Here is the working code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.functions.conversions; /*[1]*/
	function datecdash2sdtm(indate $) $; /*[2]*/
		length outdate $10; /*[3]*/
		cdash_date_regex = prxparse("/(UN|\d{1,2}) (\w{3}) (\d{4})/");

		if prxmatch(cdash_date_regex, indate) then
			do;
				yyyy = prxposn(cdash_date_regex, 3, indate); /*[4]*/
				mmm = prxposn(cdash_date_regex, 2, indate);
				dd = prxposn(cdash_date_regex, 1, indate);

				/* if year not missing */
				if notdigit(strip(yyyy)) = 0 then
					do;
						/*[5]*/
						mm = put(mmm, $month.); /*[6]*/

						/* if month not missing */
						if mm ne ' ' then
							do;
								/* if day not missing */
								if notdigit(strip(dd)) = 0 then
									do;
										dd = put(input(dd, 2.), z2.);
										/*[5]*/
										outdate = catx("-", yyyy, mm, dd); /*[7]*/
									end; /* if notdigit(dd) = 0 */
								else outdate = catx("-", yyyy, mm);
							end; /* if mm ne ' ' */
						else outdate = strip(yyyy);
					end; /* if notdigit(yyyy) = 0 */
				else outdate = ' ';
			end; /* if indate ne ' ' */
		else outdate = ' ';
		return(outdate); /*[8]*/
	endsub; /*[9]*/
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Aug 2019 13:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-proc-fcmp-compatible-with-regular-expressions/m-p/579368#M75584</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2019-08-06T13:44:07Z</dc:date>
    </item>
  </channel>
</rss>

