Desktop productivity for business analysts and programmers

How to create a macro variable into a macro function containing special characters

Accepted Solution Solved
Reply
Regular Contributor
Posts: 172
Accepted Solution

How to create a macro variable into a macro function containing special characters

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


Accepted Solutions
Solution
3 weeks ago
Super User
Posts: 2,073

Re: How to create a macro variable into a macro function containing special characters

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


All Replies
Solution
3 weeks ago
Super User
Posts: 2,073

Re: How to create a macro variable into a macro function containing special characters

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.;
Regular Contributor
Posts: 172

Re: How to create a macro variable into a macro function containing special characters

Posted in reply to novinosrin
Thanks for your help
Super User
Super User
Posts: 8,289

Re: How to create a macro variable into a macro function containing special characters

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

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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