|
On Wed, 18 Feb 2009 14:52:24 -0800, Ezra Barzilay <ezra.barzilay@GMAIL.COM>
wrote:
>New to REGEX and ignorant of PERL syntax (and thus PRX Functions), I
>am (slowly) learning how to use the RX Functions that SAS provides.
>
>I am a bit stuck with the following: I am trying to identify a pattern
>that starts with an optional "AAC" or "G", an optional dash, followed
>by a 0 or 9, a number between 0 and 9 another dash and 4 (but no more)
>alphanumeric characters.
...
hi, Ezra,
below is my try. I found that in 9.2, sas rx's are deprecated. But you can
see rxparse function documentation in 9.1 at http://tinyurl.com/c9lftm or
http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000331192.htm
another documentation still around is available at:
ftp://ftp.sas.com/pub/neural/rx612.txt . ran on 9.2 on windows.
cheers,
chang
/* optional "AAC" or "G",
an optional dach ("-"),
followed by a digit (either 0 or 9),
another digit (any),
another dash,
and no more than 4 alphanumeric characters */
%let an = a-zA-Z0-9;
data _null_;
retain prx "/(AAC|G)?-?[09]\d-[&an]{4}\b/"
rx "{'AAC'|'G'} {'-'} $'09' $d '-' $'&an' $2 $2 $2 (^2|@0)";
infile cards firstobs=2;
input var $char20.;
prxMatched = ifc(prxmatch(prx, var), "Y", "N");
rxMatched = ifc(rxmatch(rx, var), "Y", "N");
put prxMatched= rxMatched= var=;
cards;
----+----1----+----2
01-A2345
01-A234 5
01-A234
AAC-99-ABCD E
;
run;
/* on log
NOTE: The RXSTYLE, RXPATTERN, RXPATMOD, RXNEXT,
and RXSHOW functions are unsupported. Consider
using the PRX functions instead.
prxMatched=N rxMatched=N var=01-A2345
prxMatched=Y rxMatched=Y var=01-A234 5
prxMatched=Y rxMatched=Y var=01-A234
prxMatched=Y rxMatched=Y var=AAC-99-ABCD E
*/
|