I have a large dataset where one column contains free text. I wish to create a new column based on whether this free text contains a regular expression.
Eg: I want to know whether this column contains the text GnRH, or those letters in any case, and create a new column with a flag to indicate if this is true or not.
CodePudding user response:
Try this
data have;
input text $20.;
datalines;
Not in this line
In GnRH this line
Not here either
This one GNRH too
;
data want;
set have;
dummy = prxmatch('/gnrh/i', text) > 0;
run;
CodePudding user response:
FIND or INDEX work as well, and slightly easier to understand.
DUMMY = find(text, "gnrh", 'it') > 0;