BookmarkSubscribeRSS Feed
gzr2mz39
Quartz | Level 8
I have the following data:
number location
1 a
2 b
3 c

I would like to create a single html file (test.html) where (for example) test.html/#2 would should:
number=2
location
b

Is this possible to do with ods html and
proc print;by number;var location;run;
Or is there another procedure that I need to use to get these results?
Thank you.
5 REPLIES 5
Cynthia_sas
SAS Super FREQ
Hi:
According to the HTML specification, if you have an <A> tag like this:
[pre]
<a name="section"></a>
[/pre]

Then you are defining a named attribute (in this case, section) and therefore, any reference to
filename.html#section would allow navigation directly to that named section, assuming that the browser was compliant with the HTML spec.
http://www.w3schools.com/html/html_links.asp
[quote from above page]
When the name attribute is used, the <a> element defines a named anchor inside a HTML document.

Named anchor are not displayed in any special way. They are invisible to the reader.
[endquote]

That is the HTML specification. ODS actually inserts name attributes into your ODS HTML output file. The default NAME= attribute starts with 'IDX' and looks like this:
[pre]
<a name="IDX"></a> (for the first output table)
<a name="IDX1"></a> (for the second output table)
<a name="IDX2"></a> (for the third output table)
[/pre]

.... and the numbering continues from there...

If you use the CONTENTS= and FRAME= options, then ODS builds an HTML FRAMESET file that uses the CONTENTS= file and the BODY= file to display inside an HTML frame. Even if you do NOT use CONTENTS= or FRAME=, ODS still inserts the IDX NAME= attributes into the file.

After you create your HTML file with ODS, you would have to look at the file with NOTEPAD to see the use of the NAME=IDX, NAME=IDX1, etc. For example, if I run this code:
[pre]
data numloc;
infile datalines;
input number location $;
return;
datalines;
1 a
2 b
3 c
;
run;

ods listing close;
** default named section #IDX, #IDX1, #IDX2;
ods html file='c:\temp\default.html' style=sasweb;
proc print data=numloc noobs;
by number;
var location;
run;
ods html close;
[/pre]

Then this is what I would see in NOTEPAD when I examine the HTML file:
(some HTML tags deleted to only show relevant sections):
[pre]
<a name="IDX"></a>
<div class="c Byline">number=1</div>

<th class="l Header" scope="col">location</th>
<td class="l Data">a</td>


<a name="IDX1"></a>
<div class="c Byline">number=2</div>

<th class="l Header" scope="col">location</th>
<td class="l Data">b</td>


<a name="IDX2"></a>
<div class="c Byline">number=3</div>

<th class="l Header" scope="col">location</th>
<td class="l Data">c</td>

[/pre]

You can alter the string that is used for the NAME= attribute by using the ANCHOR= option in your ODS HTML invocation statement. To alter the string used for NAME=, you would submit an invocation statement something like one of these:
[pre]
ods html file='c:\temp\use_anchor_w.html' anchor='wombat'
style=sasweb;

ods html file='c:\temp\use_anchor.html' anchor='wombat10'
style=sasweb;

ods html file='c:\temp\use_anchor.html' anchor='1'
style=sasweb;

[/pre]

for the above invocations, the following NAME= sections would be created:
--ANCHOR='wombat' will make NAME= wombat, wombat1, wombat2
--ANCHOR='wombat10' will make NAME= wombat10, wombat11, wombat12
--ANCHOR='1' will make NAME= 1, 2, 3

Of course, now that the NAME= attributes are in the file, you will have to properly construct the HREF= attribute to link directly to that section. Again, looking to the W3C for guidance, the correct way to reference a NAME= section is not with a slash (/) in the HREF= attribute.
[quote from w3c site]
Example:
A named anchor inside an HTML document:

<a name="tips">Useful Tips Section</a>

A link to the Useful Tips Section from the same document:

<a href="#tips">Jump to the Useful Tips Section</a>

A link to the Useful Tips Section from another document:

<a href="http://www.w3schools.com/html_tutorial.htm#tips">
Jump to the Useful Tips Section</a>


[endquote]

Note that none of these examples contain a slash before the # reference to the NAME= section.

The insertion of a NAME= attribute is not related to any particular procedure -- it is part of how ODS constructs an HTML output file. Every output table created by your procedure will get a NAME= section. If your procedure creates 3 tables (which is what happens with the data you describe) then you would get three NAME= attributes. If your procedure of choice only creates 1 output table, then you would only get one NAME= attribute in the HTML file.

cynthia
gzr2mz39
Quartz | Level 8
Great. Thank you for this information.

I tried the code out and I got this to work:
'href="http://test.com/zipinfo.html#IDX20" target=_blank';

However, this doesn't work (the variable count is 1,2,3, etc):
href="http://test.com/zipinfo.html#IDX'||trim(left(count))||' target=_blank';

Any ideas? Thank you.
Cynthia_sas
SAS Super FREQ
Hi:
I guess I don't understand -WHERE- or -HOW- you're trying to build the HREF= attribute??

Are you doing this in a DATA step, in PROC PRINT, in PROC REPORT?? In a SAS/GRAPH program??? Inside the HTML file??

How do you know that COUNT is going to be aligned with the #IDX numbers that SAS automatically assigns when it builds the NAME= attribute for the named sections??

cynthia
gzr2mz39
Quartz | Level 8
href= is in a data step with html='href="

I used proc sort and count+1 to create count.
I confirmed that the numbers match the NAME= attribute.

Thank you.
Cynthia_sas
SAS Super FREQ
Hi:
Are you doing something for SAS/GRAPH?? If so, this example may be useful:
http://support.sas.com/documentation/cdl/en/graphref/61884/HTML/default/gr08ods2-ex.htm

Modifying the code example a bit using SASHELP.CLASS, I can make the #IDX number use a dataset variable as shown below.

Usage-wise, I'm not sure that the "target=_blank" is going to be OK, depending on where/how you plan to use this variable value. Usually, for ODS HTML output, you use the HREFTARGET style attribute to set TARGET=_BLANK:
http://support.sas.com/kb/24/058.html

If you have questions about creating hyperlinks with ODS and/or with SAS/GRAPH, you might wish to open a track with Tech Support.
cynthia
[pre]
data testit;
length namedrill $70;
set sashelp.class;
keep name namedrill;
count+1;
namedrill=catt('HREF=','"','http://test.com/zipinfo.html#IDX',left(put(count,2.0)),' target=_blank','"');
run;

proc print data=testit;
run;
[/pre]

Produces:
[pre]
Obs namedrill Name
1 HREF="http://test.com/zipinfo.html#IDX1 target=_blank" Alfred
2 HREF="http://test.com/zipinfo.html#IDX2 target=_blank" Alice
3 HREF="http://test.com/zipinfo.html#IDX3 target=_blank" Barbara
4 HREF="http://test.com/zipinfo.html#IDX4 target=_blank" Carol
5 HREF="http://test.com/zipinfo.html#IDX5 target=_blank" Henry
6 HREF="http://test.com/zipinfo.html#IDX6 target=_blank" James
7 HREF="http://test.com/zipinfo.html#IDX7 target=_blank" Jane
8 HREF="http://test.com/zipinfo.html#IDX8 target=_blank" Janet
9 HREF="http://test.com/zipinfo.html#IDX9 target=_blank" Jeffrey
10 HREF="http://test.com/zipinfo.html#IDX10 target=_blank" John
11 HREF="http://test.com/zipinfo.html#IDX11 target=_blank" Joyce
12 HREF="http://test.com/zipinfo.html#IDX12 target=_blank" Judy
13 HREF="http://test.com/zipinfo.html#IDX13 target=_blank" Louise
14 HREF="http://test.com/zipinfo.html#IDX14 target=_blank" Mary
15 HREF="http://test.com/zipinfo.html#IDX15 target=_blank" Philip
16 HREF="http://test.com/zipinfo.html#IDX16 target=_blank" Robert
17 HREF="http://test.com/zipinfo.html#IDX17 target=_blank" Ronald
18 HREF="http://test.com/zipinfo.html#IDX18 target=_blank" Thomas
19 HREF="http://test.com/zipinfo.html#IDX19 target=_blank" William
[/pre]

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1166 views
  • 0 likes
  • 2 in conversation