/********************************************************************** * prxmatch(perl-regular-expression, source) * Searches for a pattern match and returns the position at which * the pattern is found. * * In the example, * / / : mark the beginning and end of a regular expression * | : works as "or" * \b : marks the a word boundary. * for example "/\bthe\b/" matches "the", but not "other". * * Refer to the following link for more information * http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p0s9ilagexmjl8n1u7e1t1jfnzlk.htm * * Peng Zeng (Auburn University) * 05-22-2019 **********************************************************************/ data example; input str $50.; check1 = prxmatch('/HONDA/', upcase(str)); check2 = prxmatch('/GEO METRO/', upcase(str)); check3 = prxmatch('/HONDA|CIVIC/', upcase(str)); check4 = prxmatch('/HONDA|CIVIC|GEO METRO/', upcase(str)); check5 = prxmatch('/\bHONDA\b|\bCIVIC\b|\bGEO METRO\b/', upcase(str)); datalines; Honda Chevy solu world Civic New honda old Geo new one bug gEo mEtro b metro geo ahonda civicon ; proc print data = example; run; /********************************************************************** * second example. use prxparse() to compile regular expression **********************************************************************/ data make_list; input make $50.; datalines; Honda Chevy Geo Metro civic ; proc sql; select upcase(make) into: re_make_list separated by "\b|\b" from make_list; quit; data ex2; retain patternID; input str $50.; if _n_ = 1 then patternID = prxparse("/\b&re_make_list\b/"); check = prxmatch(patternID, upcase(str)); datalines; Honda Chevy solu world Civic New honda old Geo new one bug gEo mEtro b metro geo 0 GeoMetro 2 Geo Metro ahonda civicon ; proc print data = ex2; run;