The SAS Output Delivery System and reporting techniques

ODS HTML Text url encoding problem

Accepted Solution Solved
Reply
Trusted Advisor
Posts: 1,151
Accepted Solution

ODS HTML Text url encoding problem

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;

 


Accepted Solutions
Solution
‎03-29-2016 08:41 AM
Grand Advisor
Posts: 9,335

Re: ODS HTML Text url encoding problem

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;



View solution in original post


All Replies
Grand Advisor
Posts: 9,748

Re: ODS HTML Text url encoding problem


ods text="<a href=""http://www.sas.com?%nrstr(&Ion=)Ca%%2B%%2B"")​> ODS Text2 link broken</a>";

 

Trusted Advisor
Posts: 1,151

Re: ODS HTML Text url encoding problem

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.

Solution
‎03-29-2016 08:41 AM
Grand Advisor
Posts: 9,335

Re: ODS HTML Text url encoding problem

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;



Trusted Advisor
Posts: 1,151

Re: ODS HTML Text url encoding problem

Thanks @Ksharp, looks like using URL style the % signs don't disappear.

Post a Question
Discussion Stats
  • 4 replies
  • 545 views
  • 3 likes
  • 3 in conversation