It turns out that spaces were causing notdigit conditions to no longer be satisfied. Here is the working code: 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;
... View more