Hello Valentin,
One of the possible solutions is to loop of this macro making a slight change in its code, namely output testpos as a macro variable, and loop untill testpos=0 like this:
[pre]
%macro replace (dataset = , chkvar = , search = , replace =,
newvar = );
%global tp;
data &dataset (drop = textpos) newvars;
length &newvar $ 200;
set &dataset;
textpos = index(upcase(&chkvar), upcase("&search"));
CALL SYMPUTX('tp',textpos);
oldvar = &chkvar;
if textpos ne 0 then
do;
if textpos ne 1 then
&newvar = substr(&chkvar, 1, (textpos - 1)) ||"&replace"||substr(&chkvar, (textpos+length("&search")));
else &newvar = "&replace"||
substr(&chkvar, (textpos + length("&search")));
output newvars;
end;
else &newvar = &chkvar;
output &dataset;
run;
proc print data = newvars;
title “SEARCH FOR ‘&search’ AND REPLACE WITH ‘&replace’”;
var oldvar &newvar;
run;
%mend replace;
%macro a;
%global tp;
%do %until (&tp = 0);
%replace (dataset = a, chkvar = a, search = dg, replace = yy, newvar =a );
%end;
%mend a;
data a;
a="asdgdfgdg";
b="dg";
run;
%a
[/pre]
Sincerely,
SPR
... View more