BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

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 &gtarget.;

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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 &gtarget.;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

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 &gtarget.;
Tom
Super User Tom
Super User

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.

image.png

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 934 views
  • 1 like
  • 3 in conversation