BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
blueskyxyz
Lapis Lazuli | Level 10

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;

a.JPG

how to modify the PRX to delete the word "nightmare" whose length is over 8? offer more than one method of PRX?

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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;
PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

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;
PG
blueskyxyz
Lapis Lazuli | Level 10

hi PG, thank you very much,  \b match word boundary

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 657 views
  • 2 likes
  • 2 in conversation