Hi guys, could you help to modify code since I'm not familar with PRX.
I want to extract the words including lower case letters, upper case letters and digits,(a-z,A-Z,0-9), and the length word is 8.
\w
data a; length string $200; string='Befor??e Bexfore1 Beforexx xxxxxxxx nightmare or On the End,..ed 1234(678 of abc abc12345 1234567_ 1 high'; run; data a1; length s1 $8 ; set a; do i=1 to countw(string,' '); temp=scan(string,i,' '); if prxmatch("/\w{8}?/",temp) and not index(temp,"_") then do; s1=temp; output; end; end; run;
how to modify the PRX to delete the word "nightmare" whose length is over 8? offer more than one method of PRX?
prxNext routine allows you to scan a string efficiently. Instead of using \w to mean a word character (including an underscore) and then testing for the presence of an underscore, be explicit and specify [a-zA-Z0-9]
data a1;
prxId = prxparse("/\b[a-zA-Z0-9]{8}\b/o");
set a;
start = 1; stop = -1;
call prxnext(prxID, start, stop, string, position, length);
do while (position > 0);
found = substr(string, position, length);
output;
call prxnext(prxID, start, stop, string, position, length);
end;
keep string found;
run;
prxNext routine allows you to scan a string efficiently. Instead of using \w to mean a word character (including an underscore) and then testing for the presence of an underscore, be explicit and specify [a-zA-Z0-9]
data a1;
prxId = prxparse("/\b[a-zA-Z0-9]{8}\b/o");
set a;
start = 1; stop = -1;
call prxnext(prxID, start, stop, string, position, length);
do while (position > 0);
found = substr(string, position, length);
output;
call prxnext(prxID, start, stop, string, position, length);
end;
keep string found;
run;
hi PG, thank you very much, \b match word boundary
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.