Hi,
I'm using ODS text in SAS 9.3 to write some text to an html file, and want to make a link that will look like:
a href="www.sas.com?&Ion=Ca++"
Because I have those silly plus signs to deal with, I need to URL encode them to:
a href="www.sas.com?&Ion=Ca%2B%2B"
But when I do this with ODS text I end up with no % signs in the html file, I get:
a href="www.sas.com&Ion=Ca2B2B"
Which doesn't work at all.
Below code I try both hard coding the %2B and using URLENCODE() inline. Both work in the title statement but not ODS text.
What am I missing? Shouldn't this work?
ods html file="d:\junk\myhtml.html";
title1 "<a href=""http://www.sas.com?%nrstr(&Ion=)%sysfunc(URLencode(Ca++))"")> Title1 link works</a>";
title2 "<a href=""http://www.sas.com?%nrstr(&Ion=)Ca%2B%2B"")> Title2 link works</a>";
ods text="<a href=""http://www.sas.com?%nrstr(&Ion=)%sysfunc(URLencode(Ca++))"")> ODS Text1 link broken</a>";
ods text="<a href=""http://www.sas.com?%nrstr(&Ion=)Ca%2B%2B"")> ODS Text2 link broken</a>";
proc print data=sashelp.class (obs=1);
run;
ods html close;
Quentin, How about using URL Style ? %let ionlist=Ca++|Na+; %let I=%nrstr(http://www.sas.com?&Ion=)%sysfunc(URLencode(&ionlist)); %put &i ; ods escapechar='~'; ods text="~S={url='&i'}ODS Text2 link broken"; proc print data=sashelp.class; run;
ods text="<a href=""http://www.sas.com?%nrstr(&Ion=)Ca%%2B%%2B"")> ODS Text2 link broken</a>";
Thanks @ballardw that works. Curious why the extra % is needed in ODS Text?
And more importantly, is there any way to get this working with URLENCODE()?
Currently I've get a data-generated macro variable &ionList with value like : Ca++|Na+
which I URLENCODE(). I suppose I could double up the % signs myself like:
%let ionlist=Ca++|Na+;
%put %sysfunc(transtrn(%sysfunc(URLencode(&ionlist)),%,%%));
But feels silly.
Quentin, How about using URL Style ? %let ionlist=Ca++|Na+; %let I=%nrstr(http://www.sas.com?&Ion=)%sysfunc(URLencode(&ionlist)); %put &i ; ods escapechar='~'; ods text="~S={url='&i'}ODS Text2 link broken"; proc print data=sashelp.class; run;
Thanks @Ksharp, looks like using URL style the % signs don't disappear.
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 25. 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.