The SAS Output Delivery System and reporting techniques

Unable to give hyperlink to a word in a sentence ...please help....

Reply
New Contributor
Posts: 4

Unable to give hyperlink to a word in a sentence ...please help....

Hi All,

I had a situation where i need to provide a hyperlink to a particular word in a sentence when output in html. For example:
"A Professional SAS Programmer."
and I need to give the hyperlink to "Professional" and am able to give the link to the whole sentence but not for the particular word i needed.

Below is the code am using:

A Professional SAS Programmer.

and its giving the exact html code in the output rather than hyperlink and when i checked the HTML source code it is as below:

A <a target='_blank'href='http://en.wikipedia.org/wiki/Professional'>Professional</a> SAS Programmer.

Please Help...

Thanks In Advance...
Solo
SAS Super FREQ
Posts: 8,743

Re: Unable to give hyperlink to a word in a sentence ...please help....

Hi:
You show the HTML code you are using, but not the SAS code you are using. Your use of HTML implies that your destination of choice is ODS HTML, but it would be useful to see your SAS code, plus your ODS code. Seeing your SAS code would help determine whether you are writing DATA step code, using PROC PRINT, PROC REPORT or ...???

When you post code with HTML tags or < symbols or > symbols, you need to protect those HTML symbols from the forum posting mechanism mistakenly interpreting them as HTML tags aimed at formatting your post (instead of being just part of the code). You will need to use search and replace prior to posting in order to
1) convert the < symbol to &lt; (ampersand-lt-semicolon)
and
2) convert the > symbol to &gt; (ampersand-gt-semicolon)

Meanwhile, the code below is an example that works for me.

cynthia
[pre]
data class;
length job $125;
set sashelp.class;
where name in ('Alfred', 'Barbara');
if name = 'Alfred' then
job = catx(' ',"A <a target='_blank' href='http://en.wikipedia.org/wiki/Professional'>Professional</a>",' SAS programmer');
if name = 'Barbara' then
job = catx(' ',"A Professional <a target='_blank' href='http://www.sas.com'>SAS</a>",'programmer');
run;

ods listing close;
ods html file='c:\temp\use_url_word.html' style=sasweb;

proc print data=class noobs
style(data)={protectspecialchars=off};
var name age sex height weight job;
run;

ods html close;
[/pre]
New Contributor
Posts: 4

Re: Unable to give hyperlink to a word in a sentence ...please help....

Hi Cynthia...First of all thanks a lot for the response.


Below is the SAS code am using to set the hyperlink to the word "Professional":





filename seercode URL "http://www.bestsampleresume.com/resume-templates/sample-accounting-resume-template-1.html" debug lrecl=32767;



data html1(drop= v v1 rx1);

infile seercode truncover;

input @1 v $32767.;

format v1 v2 $32767.;

v1=htmldecode(v);

if substr(v1,1,3)='<p>' or substr(v1,1,3)='<B>' or
substr(v1,1,4)='<br>' or substr(v1,1,4)='</B>' or substr(v1,1,4)='<LI>' or substr(v1,1,8)='<CENTER>';

v2=v1;

rx1=prxparse("s/<(.|\n)*?>//");


call prxchange(rx1,-1,v2);/* Performs a pattern-matching replacement and -1 indicates replace all the pattern available */

if v2=' ' then delete;

run;




data html2;

length x $32767;

set html1;

x=tranwrd(v2,'Professional',cat('<a target=',"'_blank'",' href="http://en.wikipedia.org/wiki/Professional">Professional'));

run;




ods html body='C:\Documents and Settings\sasadm\Desktop\resume.html' style=minimal;




data _null_;

set html2;

file print;

put x;

run;



ods html close;




Thanks In Advance...

Solo Message was edited by: Solo
New Contributor
Posts: 4

Re: Unable to give hyperlink to a word in a sentence ...please help....

Hi Cynthia,

Thanks ...its working by using the "style(data)={protectspecialchars=off}"

Its working in proc print.So is there any way to use this by the _null_ and file print?



Thanks a lot


Solo
SAS Super FREQ
Posts: 8,743

Re: Unable to give hyperlink to a word in a sentence ...please help....

Hi:
This is the incorrect syntax for working with ODS and FILE PRINT:
[pre]
file print;
[/pre]

You should be using:[pre]
file print ods;
[/pre]

But that would still not change your issue of how to pass in the protectspecialchars=off. If you really WANT to use DATA _NULL_, you would have 3 choices:
1) abandon the ODS HTML "sandwich" and write ALL your HTML tags in the DATA step program. In this case, the FILE PRINT with PUT statements (a very useful technique when you want to create an output file) would create a plain ASCII text file and the issue of "protection" of special characters would become irrelevant.
or
2) try to change the style template to add PROTECTSPECIALCHARS=OFF to the DATA element (and change your syntax to use FILE PRINT ODS -- so you actually have a DATA element in the resulting output)
or
3) create a custom TABLE template for use with you DATA _NULL_ technique, as illustrated in this paper (you can add style overrides to your DEFINE/END block of code): http://www2.sas.com/proceedings/sugi30/088-30.pdf

But, to me, it is far simpler to use PROC PRINT and a simple STYLE= override than to learn the DATA _NULL_ required for #1; the STYLE template and new syntax required for #2; or the TABLE template and new syntax required for #3. IMHO, ODS makes your life so much easier because you CAN use STYLE= overrides with PROC PRINT in order to pass a URL to an HTML file created by ODS.

cynthia

Using the previously posted data from SASHELP.CLASS, an example of #1 technique would be (WITHOUT any ODS HTML statements) -- essentially, this technique is how a programmer would write ASCII text HTML files from SAS datasets in the "old" days -- before ODS:
[pre]

** DATA _NULL_ to write ALL HTML tags;
data _null_;
file 'c:\temp\myexamp.html';
set class end=eof;
if _n_ = 1 then do;
put @1 '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">';
put @1 '<html><head><title>my example</title></head><body>';
put @3 '<center><table border=1><thead>';
put @5 '<tr><td><b>Name</b></td><td><b>Age</b></td><td><b>Job</b></td></tr></thead><tbody>';
end;
put @5 '<tr><td>' Name '</td><td>' Age 2.0 '</td><td>' Job '</td></tr>';
if eof then do;
put @3 '</center></tbody></table></body></html>';
end;
run;
[/pre]
New Contributor
Posts: 4

Re: Unable to give hyperlink to a word in a sentence ...please help....

Hi Cynthia,


Thanks for the Help and for providing the details.


Regards

Solo
Ask a Question
Discussion stats
  • 5 replies
  • 219 views
  • 0 likes
  • 2 in conversation