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;
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 %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
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 %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
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).
hi
There are the HTMLENCODE / HTMLDECODE functions, but they will not encode the % sign, they will others.
Bruno
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: