2 examples:
1. using a hash map and iterator
2. using the point option in a set statement, that one is probably easier to understand.
data search;
length search_term $10;
input search_term;
cards;
botox
ibuprofen
paracetamol
;
data names;
length name $30;
infile cards truncover dlm=',';
informat name $char30.;
input name ;
cards;
botox b
ipren (ibuprofen)
pamol (paracetamol)
glp-1
insulin
;
run;
/* data step using a hash map and an iterator */
data match;
if _N_ = 1 then do;
length search_term $10;
declare hash hmap (dataset: 'work.search');
declare hiter search ('hmap');
rc = hmap.definekey('search_term');
rc = hmap.definedata('search_term');
call missing(search_term);
rc = hmap.definedone();
end;
set names;
found = 0; /* Search indicator, 0=no hit, 1=one or more hits */
rc = search.first();
do while (rc = 0);
if find(name,search_term,'it') > 0 then do;
/* Found the search_term in the name column */
found = 1;
rc = -1; * Stop searching;
end;
else rc = search.next();
end;
if found = 0 then search_term = '';
drop rc;
run;
/* data step using the point= option */
data match;
set names;
found = 0;
do i=1 to searchobs;
set search point=i nobs=searchobs;
if find(name,search_term,'it') > 0 then do;
found = 1;
leave; * Stop searching;
end;
end;
if found = 0 then search_term = '';
drop i ;
run;
... View more