Hello,
I have tried the following code and it works.
But when I put it in a macro function, it failed.
The idea is to replace the " sign in the prolog from an xml file by %bquote(") to make sure that the macro variable has an acceptable structure.
%let prolog1=<?xml version="1.0" encoding="windows-1252" ?>;
%let target='"';
%let replacement=%bquote(");
%let prolog1=%sysfunc(tranwrd(%quote(&prolog1.),&target.,&replacement.));
%put &prolog1;
I would like to do the same thing but in a macro function such as:
%macro test;
%global gtarget greplacment gprolog;
%let prolog1=<?xml version="1.0" encoding="windows-1252" ?>;
%let target='"';
%let gtarget = &target.;
%let replacement=%bquote(");
%let greplacment= &replacement.;
%let prolog1=%sysfunc(tranwrd(%quote(&prolog1.),&target.,&replacement.));
%let gprolog=&prolog1.;
%mend test;
%test;
%put &gprolog.;
%put &greplacement.;
%put >arget.;
Corrected:
%macro test;
%global gtarget greplacement gprolog;
%let prolog1=<?xml version="1.0" encoding="windows-1252" ?>;
%let target='"';
%let gtarget = &target.;
%let replacement=%str(%");
%let greplacement=( &replacement.);
%let prolog1=%sysfunc(tranwrd(%quote(&prolog1.),&target.,( &replacement.)));
%let gprolog=&prolog1.;
%mend test;
%test;
%put &gprolog.;
%put &greplacement.;
%put >arget.;
Corrected:
%macro test;
%global gtarget greplacement gprolog;
%let prolog1=<?xml version="1.0" encoding="windows-1252" ?>;
%let target='"';
%let gtarget = &target.;
%let replacement=%str(%");
%let greplacement=( &replacement.);
%let prolog1=%sysfunc(tranwrd(%quote(&prolog1.),&target.,( &replacement.)));
%let gprolog=&prolog1.;
%mend test;
%test;
%put &gprolog.;
%put &greplacement.;
%put >arget.;
I have tried the following code and it works.
But when I put it in a macro function, it failed.
The idea is to replace the " sign in the prolog from an xml file by %bquote(") to make sure that the macro variable has an acceptable structure.
That will not actual apply macro quoting to the quotes, since the use of %SYSFUNC() instead of %QSYSFUNC() will remove the macro quoting.
If you just want to quote the special characters in the input then use a regular macro quoting function.
%let prolog3=%superq(prolog1);
As you can see it this picture the value of PROLOG3 has macro quoting and the value of PROLOG1 and PROLOG2 don't.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.