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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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