@martyvd wrote:
I confirmed that the statenames macro variable contains only the names of 50 states + DC with no duplicates.
Yes, I am really trying to look through text to see if one or more state names appear. My objective is to identify records where individuals may have entered personal information such as their location. I am not concerned about where state names may appear in compound words. Flagging those may actually be helpful.
If you want to directly search if ANY of a list of values appears in free text then a regular expression is probably going to be the shortest code. The pipe character is used in a regular expression to list a set of alternative possible matches.
Example:
data have;
infile cards dsd truncover ;
input (var1 var2) (:$30.) ;
cards;
I live in Alabama,
,My blood pressure is high
I live in Kansas,My blood pressure is low
;
data want ;
set have;
found=0<prxmatch('/\b(alabama|alaska|arkansas)\b/i',catx(' ',of var1-var2));
run;
Result
OBS var1 var2 found
1 I live in Alabama 1
2 My blood pressure is high 0
3 I live in Kansas My blood pressure is low 0
You could have the list of states in a macro variable:
%let states=alabama|alaska|arkansas;
data want ;
set have;
found=0<prxmatch("/\b(&states)\b/i",catx(' ',of var1-var2));
run;
... View more