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

Once again I have struggled with an issue for ages, and could find an exact answer anywhere.

So my problem is that I need to use a macro variable inside ODS TEXT statement. The unfortunate part is that the macro variable could contain %-sign and it causes whole lot of issues. I have tried literally every trick I know and beyound.

Everything is fine when I use %SUPERQ with the macro variable, but when I do that in ODS TEXT it has no effect. I have attached a small example what I have trying to achieve.

data testing;
text='Some text %and some more';
call symput('mvar',text);
run;

%*Works like a charm;
%put %superq(mvar);

%*None of these work;
ods html;
ods text="<p class=""bold"">%superq(mvar)</p>";

%*This is not even possible?;
/*ods text=%nrbquote("<p class=""bold"">%superq(mvar)</p>");*/

ods text=%nrstr("<p class=""bold"">%superq(mvar)</p>");

ods text="<p class=""bold"">""&mvar.""</p>";

ods html close;
1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Hi

 

I think this is not really  SAS macro related, but rather the %A is somehow used by HTML.

 

You should change the % sign to the HTML Entity representation.

 

See here an example:

 

data testing;
  length text $ 1024;
  text='Some text %sugus some more';
  call symputx('mvar1',text);
  text='Some text %and some more';
  call symputx('mvar2',text);
  text='Some text &#37;and some more';
  call symputx('mvar3',text);
run;

%put %superq(mvar1);
%put %superq(mvar2);
%put %superq(mvar3);

ods html file="c:\temp\sometext.html";

ods text="<p class=""bold"">%superq(mvar1)</p>";
ods text="<p class=""bold"">%superq(mvar2)</p>";
ods text="<p class=""bold"">%superq(mvar3)</p>";

proc print data=sashelp.class(obs=1);
run;

ods html close;

You can find a list of the HTML Entities here https://dev.w3.org/html5/html-author/charref

 

Bruno

View solution in original post

3 REPLIES 3
BrunoMueller
SAS Super FREQ

Hi

 

I think this is not really  SAS macro related, but rather the %A is somehow used by HTML.

 

You should change the % sign to the HTML Entity representation.

 

See here an example:

 

data testing;
  length text $ 1024;
  text='Some text %sugus some more';
  call symputx('mvar1',text);
  text='Some text %and some more';
  call symputx('mvar2',text);
  text='Some text &#37;and some more';
  call symputx('mvar3',text);
run;

%put %superq(mvar1);
%put %superq(mvar2);
%put %superq(mvar3);

ods html file="c:\temp\sometext.html";

ods text="<p class=""bold"">%superq(mvar1)</p>";
ods text="<p class=""bold"">%superq(mvar2)</p>";
ods text="<p class=""bold"">%superq(mvar3)</p>";

proc print data=sashelp.class(obs=1);
run;

ods html close;

You can find a list of the HTML Entities here https://dev.w3.org/html5/html-author/charref

 

Bruno

BobHope
Quartz | Level 8

Well thank you for the answer. That was indeed the problem in this case. However at least I get an warning on the log too that could not resolve macro %macroname if there is a % sign inside the ods text. So the next question is if my ods destination isn't html but something else how can I bypass that? Well that is more of a philosophical question since I got my issue solved.

Do you happen to know if there is a function in SAS which automatically translates special characters into HTML entities? The problem is that the text can contain basically any special character and I definately wouldn't want to hard code the transformation in every case.

 

Thanks again!

 

EDIT: Found the HTMLENCODE function, but unfortunately it does not encode all characters (especially % is missing).

BrunoMueller
SAS Super FREQ

hi

 

There are the HTMLENCODE / HTMLDECODE functions, but they will not encode the % sign, they will others.

 

Bruno

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2264 views
  • 1 like
  • 2 in conversation