BookmarkSubscribeRSS Feed
Soundappan
Fluorite | Level 6

Hi I am trying to create a PDF hyperlink using t.format_cell method. But one the URL path contains '#' symbol and because of it the hyperlink generated becomes invalid. And the URL generated do not contain the text/path after '#' symbol.

 

In the example below, the actual File path is 'file:///test/file/path/Information #51801.msg' but in PDF generated it is 'file:///test/file/path/Information '

 

URL_Error.PNG

Code:

%let file_name ='Additional Information';
%let url_path = 'file:///test/file/path/Information #51801.msg';

proc template;
	define style work.sample;
	parent=styles.pearl;

style TableBase/
     cellpadding=2pt
     verticalalign=top
    ;

style TextUnderline from Body  /
     borderbottomcolor=black
     borderbottomwidth=1pt
     textindent=10
     height=20pt
     fontsize=8pt
    ; 
	end;
run;
%put %STR(NOTE: Build the report ... );

ods escapechar='~';
%let outpath=/sas_data/pdf_location;
ods pdf 
  file="&outpath./output_file.pdf"   
  ;

ods trace on/ label;
data _null_;
declare odsout t();

 t.table_start( name: 'Attachments', style: 'TableBase', overrides: 'width=190mm');

   t.row_start();
      t.format_cell(Text: "" );
      t.format_cell(text: &file_name
          , style: 'TextUnderline'
          , url: &url_path, overrides:"color=blue" 
          ,overrides:'');
  t.row_end();
 t.table_end();
run;
ods pdf close;
4 REPLIES 4
jimbarbour
Meteorite | Level 14

I think the problem is the embedded blank not the # sign.  Try getting rid of the embedded blank.

 

Jim

Soundappan
Fluorite | Level 6

Hi Jim,

 

Thanks for responding. No it did not work, the black space is getting parsed without issue, but when it comes to '#' symbol, it get cutoff.

 

Actual URL Path - 'file:///test/file/path/Information doc#51801.msg'

URL in PDF - 'file:///test/file/path/Information doc'

 

URL generated in PDF,

URL_Error1.PNG

 

Thanks,

Soundappan

Kurt_Bremser
Super User

From the wikipedia article for URL/URI:

  • An optional fragment component preceded by a hash (#). The fragment contains a fragment identifier providing direction to a secondary resource, such as a section heading in an article identified by the remainder of the URI. When the primary resource is an HTML document, the fragment is often an id attribute of a specific element, and web browsers will scroll this element into view.

As you can see, the hash sign has a special meaning in URI's and must not be used for anything else.

(When you define an anchor in a HTML page, the # syntax is used to place the browser directly there)

Bottom line: don't use special characters in filenames, unless you want to run into trouble later.

jimbarbour
Meteorite | Level 14

@Soundappan wrote:

Thanks for responding. No it did not work, the black space is getting parsed without issue, but when it comes to '#' symbol, it get cutoff.

 

Actual URL Path - 'file:///test/file/path/Information doc#51801.msg'

URL in PDF - 'file:///test/file/path/Information doc'

Interesting.  Well, I think @Kurt_Bremser's admonition to not use a "#" symbol because it has special meaning is probably sound.

 

Jim

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1391 views
  • 1 like
  • 3 in conversation