Hi,
I have a dataset with a variable called description. A description may contain zero, one or many names matching names in a list called namelist. I'm trying to search description for these names and, when found, create new variables containing them called name1, name2, name3, etc. For the matching algorithm I'm using regular expression. I'm open to other algorithms but I'd like to keep the flexibility of the regular expression.
How to go about this? I got started but got stuck. Here are my codes. I don't think I am using symput correctly. Furthermore, I'm not even sure that I need to be dealing so much with the macro facility here. Perhaps it's better to stick with the datastep.
I have a dataset with a variable called description. A description may contain zero, one or many names matching names in a list called namelist. I'm trying to search description for these names and, when found, create new variables containing them called name1, name2, name3, etc. For the matching algorithm I'm using regular expression. I'm open to other algorithms but I'd like to keep the flexibility of the regular expression.
How to go about this? I got started but got stuck. Here are my codes. I don't think I am using symput correctly. Furthermore, I'm not even sure that I need to be dealing so much with the macro facility here. Perhaps it's better to stick with the datastep.
Code:
%macro mysearch;
%data outdata;
%set indata;
%let p = 0;
%do n = 1 %to 30/*number of names in name list*/;
match = %match(%scan(&namelist, &n),description);
call symput('q', match);
%let p = %eval(&p + &q);
if %match(%scan(&namelist, &n),description) ne 0 and if &p > 0 and if name&p ne "" then name&p = %scan(&namelist, &n)";
%end;
run;
%mend; %mysearch;
%macro match(match_text, match_in);
%let match = prxmatch(prxparse("/&match_text\b/"),lowcase(&match_in));
&match
%mend;