As I see, each input observation has at most one one required substring. Is it?
In such case there is no need to look for or concatenate input required substrings.
Check next code:
data cl_3;
input CLORRES $char80.;
cards;
discolored.redish
preset.condition.foamy.yellowish/greenish
preset.condition.mucous.white
preset.condition.foamy.yellowish/greenish
preset.condition.food contents.while
; run;
%let strings = yellowish / greenish,food contents,dark;
%let dlm = ,;
Data cl_test3;
set cl_3;
length search_for $20 search $140; /* adapt length if need */
retain search nums;
if _N_ = 1 then do;
search = "&strings"; /* assuming no double quotes in string */
nums = countw(search,"&dlm"); put nums=;
end;
length new_var $200; /* adatpt to max length expected */
new_var = ' '; /* initialize for each observation */
do i=1 to nums;
search_for = strip(scan(search,i,"&dlm")); put search_for=;
if index(CLORRES,strip(search_for)) > 0 then do;
new_var = search_for;
output;
end;
end;
keep clorres new_var;
RUN;
PAY ATTENTION -
1) In the substring list you asked for "yellowish / greenish" (with spaces around the slash)
while the input row is "preset.condition.foamy.yellowish/greenish" (no spaces).
You have to adapt the list of substrings or use compress on both sides.
2) Is your input data realy compressed, without spaces and the only delimiter between substrings is a dot "."?
3) So we are talking about two different delimiters:
(1) delimiter used in %LET statement, separating required substrings
(2) delimiter used in the input data to separate between the substrings.
... View more