BookmarkSubscribeRSS Feed
napat
SAS Employee

I want to search for a list of words in a long text in a column (. If any word in the list exists in the column, the row be in the output dataset.

 

Please see my partial code. 

I want to search for dog,cat and boat in a column called "Column"

 

 

 

WL = PRXPARSE("/dog|cat|boat/");

do i=1 to N;

    position = PRXMATCH( WL ,Column(i));
    if position ge 1 then do;

           ALERT_TRIGGER_TXT= SUBSTR(Column(i),max(1,position-200),position-1)|| '*' ||                          

          SUBSTR(A_TSC_SUSP_TXT(i),max(1,position),position+200) ;
          output;
    end;
end;

 

Is there other text searching function that would make the program faster? 

 

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I would do - without test data (form of a datastep) and required output - :

data want;
  set have;
  do i="DOG","CAT","BOAT";
    if index(upcase(<your string variable>),i) > 0 then do;
      found=1;
      leave;
    end;
  end;
run;
Kurt_Bremser
Super User

I guess that you will be mostly I/O bound, but you could try

 

%let list=dog,cat,boat;

data want;
set have;
indicator = 0;
do i = 1 to countw("&list",',');
  if indexw(column,scan("&list",i,',')) > 0 then indicator = 1;
end;
if indicator then output;
drop indicator i;
run;

just to compare runtimes.

data_null__
Jade | Level 19

You need to supply data and a complete example program.

 

PRXPARSE is slow and should only be done one time and retain the RC for use in PRXMATCH.  See the exampes in the documentation where they use the RETAIN statement and IF _N_ eq 1 THEN ....

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
  • 3 replies
  • 1622 views
  • 0 likes
  • 4 in conversation