3
votes

With ODS HTML in SAS, I would like to create anchors to titles so that I could refer to those anchors from tables.

Currently I have been able to create references in the tables:

proc sql;
select '<a href="#'||m.anchor_text||'">'||m.anchor_text||'</a>'
  from matrix m;
quit;

which in HTML browser output will show as internal links to the HTML file:

anchor1  <-- this is a href link to anchor1
anchor2  <-- this is a href link to anchor2

When I now tried to create anchors to the actual data tables:

title "<a name='anchor1'></a>Data on matrix1";
proc sql;
select * from matrix1;
quit;

The title does not wrap the text into an anchor, but instead shows the full HTML code:

<a name='anchor1'></a>Data on matrix1
(matrix1 data here)

If I look the HTML code, I can see that the title characters are translated to be showable in HTML:

&lt;a name=&#39;anchor1&#39;&gt;&lt;/a&gt;Data on matrix1

But how could create such an HTML anchor into the title of a proc sql query i.e. embed HTML tags into title?

3

3 Answers

4
votes

You have a few options here, depending on what's easiest for your general usage.

First, you could go into the template, and add for each title element's template a prehtml and/or posthtml entry. This would mean that every time Title1 was used, you got the same anchor tag (until you reran proc template anyway). That would be useful if you wanted title# to always have the same anchor despite sometimes variable text.

Second, you can use the raw style option. ^{raw <a href="#anchor1"></a>}, assuming your ods escapechar is ^. You also can use ^R/HTML{..}, I believe. See the documentation, and Cynthia Zender's classic paper Funny Stuff in My Code. This is the better option if every title needs a different anchor (as you can specify it each time, but you also need to specify it each time).

Third, you could use the first option along with a macro variable, I believe (similar to how you did the previous contentitem) that defines the value of the anchor. This is more 'in theory' but could be the best of the three.

4
votes

In all ODS HTML-bound output, you can wrap your HTML in a <div>...</div> to ensure SAS renders it as the correct HTML.

To create an anchor, you use <a name='anchorname'></a>, so :

title "<div><a name='anchor1'></a></div>" ;

And to reference it elsewhere in your page :

Title "<div><a href='#anchor1'>Go to Anchor 1</a></div>" ;
2
votes

EDIT: The below doesn't quite address the original question (I misread it), but may still be useful to some people. As Joe points out in the comments, it looks like SAS has different approaches on how to treat HTML anchor tags in title statements. Joe's answer is correct.


I think you simply have incorrect syntax on your anchor tag in your title statement. This works fine for me:

ods html;

title "<a href='dkjfkjdf.html'>Hello</html>";

proc print data=sashelp.class;
run;

ods html close;

Results:

I believe what you need is to move your text inside of your anchor tag (and use quotes) like so:

title '<a href="#anchor1">Data on matrix1</a>';