In the example shown below, the PRXMATCH function is used to return the position of the word "SAS" in each of the strings. PRXMATCH function is used much like the FIND function.It returns the first position in String where "SAS" is found.The PRXPARSE function is used to create a regular expression
title "Perl Regular Expression in SAS";
data _null_;
if _n_ = 1 then Pattern_num = prxparse("/SAS/");
*exact match for the letters 'SAS' anywhere in the string;
retain Pattern_num;
input String $60.;
Position = prxmatch(Pattern_num,String);
file print;
put Pattern_num= String= Position=;
datalines;
SAS is a collection of modules to process and analyze data
There are many functions used in SAS
Learning SAS is easy
Regular expressions in SAS
;
The Output would look like this:-
Perl Regular Expression in SAS
Pattern_num=1 String=SAS is a collection of modules to process and analyze data Position=1
Pattern_num=1 String=There are many functions used in SAS Position=34
Pattern_num=1 String=Learning SAS is easy Position=10
Pattern_num=1 String=Regular expressions in SAS Position=24
The value of Position is the location of the letter "S" in "SAS" in each of the strings