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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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

4 REPLIES 4
ballardw
Super User

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

 

Quentin
Super User

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.

Ksharp
Super User
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;



Quentin
Super User

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 4 replies
  • 3885 views
  • 4 likes
  • 3 in conversation