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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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