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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.