@JediApprentice wrote:
Here is the code. It doesn't seem to be removing (replacing with blank) the strings that I am providing as the last parameter in the macro call. Anyone have any ideas. I've tried slight variations but with no luck.
%macro word_removal(tbl_in, tbl_out, first_field, second_field, str_list);
data &tbl_out;
set &tbl_in;
%do i = 1 %to %sysfunc(countw(&str_list.));
%let current_str = %scan(&str_list., &i.);
&second_field = tranwrd(&first_field, "¤t_str.", '');
%end;
run;
%mend word_removal;
%word_removal(input_table, output_table, field_one, field_two, ('hello','world','beta','alpha'));
Thanks
You have two issues likely. First is the macro call is introducing problems with the way that you pass the list. Remove the (), the ' and commas.
Second if you want to remove ALL of the words then your logic is incorrect. You keep replacing the string from the original value. If you pass more than one word then you are currently only actually replacing the last one in the list.
%macro word_removal(tbl_in, tbl_out, first_field, second_field, str_list);
data &tbl_out;
set &tbl_in;
%do i = 1 %to %sysfunc(countw(&str_list.));
%let current_str = %scan(&str_list., &i.);
%if &i=1 %then %do;
&second_field = tranwrd(&first_field, "¤t_str.", '');
%end;
%else %do;
&second_field = tranwrd(&second_field, "¤t_str.", '');
%end;
%end;
run;
%mend word_removal;
%word_removal(Sashelp.cars,work.junk, make, newmake,Acura Audi);
Quotes and commas in a macro parameter are very often either not needed with careful planning and often a cause of problems.
... View more