The SAS Output Delivery System and reporting techniques

Send e-mail with Hyperlink

Accepted Solution Solved
Reply
Regular Contributor
Posts: 237
Accepted Solution

Send e-mail with Hyperlink

I want to send an e-mail from within SAS that includes a hyperlink.  I have found several discussions on this, but they are from 2011 and earlier.  Their suggestions don't even work--at least not on my system.  Have things changed over the last 4-5 years where I can easily add hyperlinked text to the body of an e-mail?  They hyperlink may not necessarily be a URL but rather a file directory.  I know the snipet below won't add hyperlinks, but I want to show what I am trying to do.

filename mail email

     to=("someone@somewhere.com")

     subject="Test e-mail with Hyperlink";

data _null_;

     file mail;

     put "Here is a test to see if hyperlinks work in an e-mail sent from SAS:"

     put " ";

     put "URL:  www.sas.com";          /* hyperlink web address */

     put "Directory: C:\Users\Public";     /* hyperlink path */

run;


Accepted Solutions
Solution
‎03-05-2015 10:47 AM
Super Contributor
Posts: 292

Re: Send e-mail with Hyperlink

Posted in reply to djbateman

here's an example of what I use all the time ...

filename testmsg email ' '

to =('someone@somewhere.ca')

subject=('too much fun for one day');

data _null_;

file testmsg;

put "file:\\Technology\Quality\FantasticFile.pdf";

run;

View solution in original post


All Replies
SAS Super FREQ
Posts: 8,868

Re: Send e-mail with Hyperlink

Posted in reply to djbateman

Hi:

  It was my understanding that a hyperlink was an HTTP: address, such as: http://www.sas.com -- a hyperlink path is a directory structure on the web server. So, for example, your Directory of C:\Users\Public would NEVER be a hyperlink path for www.sas.com web server.

  But let's say you have a web server address like this:

http://www.wombat.com/home/index.html which points to a specific HTML page on www.wombat.com's home directory, then this location:

http://www.wombat.com/home/morestuff/report1.html  would be located in the morestuff directory which is under the home directory. The web server file system could be Linux, could be Windows, could be Mac operating system. So you rarely know the physical directory path on the web server for an HTTP address unless you know, explicitly, what the web server's directory path structure looks like. Web admins can take horribly long physical paths like this:

/usr/public/webpart/start and /usr/public/webpart/start/morestuff and alias them on the web server to shorter HTTP paths like: www.wombat.com/home/ and www.wombat.com/hom/morestuff

  Have you tried a PUT statement like:   put "URL:  http://www.sas.com";          /* hyperlink web address */ ?

  And, your mail instructions don't contain a Content-type option, so if your mail server is a Plain text mail server by default, the URL might not come thru. But if your mail is an HTML mail, then you might see the link. It is very popular these days for mail system admins to disable hyperlinks to avoid people accidentally clicking on a link and loading bad things.

  Possibly, this is a question for Tech Support, as your mail system, SAS settings and other factors could come into play.

cynthia

Regular Contributor
Posts: 237

Re: Send e-mail with Hyperlink

Posted in reply to Cynthia_sas

I attempted to add the "http://" in front of my URL, but it still didn't work.  I'll have to contact tech support, I guess.

And hyperlinks aren't just for HTTP addresses.  You can hyperlink webpages, e-mail addresses, file directories, or even specific places in a document.  I often hyperlink my directories manually for coworkers.  When I have a folder for them to view, I can copy and paste the directory into an e-mail, highlight that directory, right-click and select Edit Hyperlink.  In the address, I just paste the directory again.  When they receive the e-mail, they see the name of the directory with a hyperlink that when clicked opens an explorer window taken directly to the folder that I want them to view.  It would be nice to have that functionality directly in SAS.

PROC Star
Posts: 1,324

Re: Send e-mail with Hyperlink

Posted in reply to djbateman

Assuming you are sending html email, I've used ODS HTML and proc report to generate html file that has table  with links in it (to both web sites and files), then stuck that html file as the body of an email sent via SAS, and it worked fine.

In Outlook, when user opens the email, they see a links, and can click to open file or go to site or whatever.  e.g.:

data me;
  input link $200.;
  cards;
www.sas.com
\\share\directory\blah.txt
;
run;

ods html file="d:\junk\me.html";
proc report data=me nowd;
  column link;
  compute link;     
    call define(_col_,'URL',link);
  endcomp;
run;
ods html close;


I would double check that your are sending email as html. Some places don't allow it anymore.

--Q.

PROC Star
Posts: 1,324

Re: Send e-mail with Hyperlink

I've also done stuff like with hand-written html body like:

If questions, email <a href='mailto:somebody@somewhere.com?Subject=question'>Somebody</a>.

Regular Contributor
Posts: 237

Re: Send e-mail with Hyperlink

Quentin,

My e-mail is set to compose in HTML.  I can create the report as you stated, but after you create it, do you attach it to the e-mail, or does it show up in the body of the e-mail?  I am currently attempting this, which provides an attachment:

data me;

  input link $200.;

  cards;

www.sas.com

\\share\directory\blah.txt

;

run;

ods html file="d:\junk\me.html";

proc report data=me nowd;

  column link;

  compute link;    

    call define(_col_,'URL',link);

  endcomp;

run;

ods html close;

filename mail email

  to=("someone@somewhere.com")

  subject="Test e-mail with Hyperlink"

  attach=("d:\junk\me.html");

data _null_;

     file mail;

     put "Here is a test to see if hyperlinks work in an e-mail sent from SAS:";

run;

PROC Star
Posts: 1,324

Re: Send e-mail with Hyperlink

Posted in reply to djbateman

Body of the email.  I have to run, but I think I do it like:

data _null_;

  file mail;

  infile 'd:\junk\me.html';

  input;

  put _infile_ ;

run.

If can try to make a little example tomorrow, if you don't have it going by then.

SAS Super FREQ
Posts: 8,868

Re: Send e-mail with Hyperlink

Posted in reply to djbateman

Usually if you're doing HTML in the body of the mail, I thought you needed Content-type. Look at the TYPE= option in this note: 6735 - E-mailing HTML output generated with ODS from a SAS® session where it has

type="text/html" (Example 1).

 

cynthia

PROC Star
Posts: 1,324

Re: Send e-mail with Hyperlink

Posted in reply to djbateman

Here's an example of using ODS to write the html file with different links, then using a data _null_ step to send the email.

data links;
  input link $20.;
 
cards;
www.sas.com
d:/junk/mycode.sas
;
run;

ods listing close;
ods html file="%sysfunc(pathname(work))/__MyHtml.htm" style=journal;

footnote1 "<span> email questions to <a href='mailto:support@sas.com?Subject=Help!'>SAS Support</a> </span>";
proc report data=links nowd;
 
col link;
  compute link;
    call define(_col_,'URL',link);
  endcomp;
run;
footnote1;

ods html close;
ods listing;

filename __mymail email
 
to="you@somewhere.com"
 
from="me@somewhere.com"
 
subject="Hello"
 
content_type="text/html"
;

data _null_;
 
file __mymail;
  infile "%sysfunc(pathname(work))/__MyHtml.htm";
 
input ;
  put _infile_ ;
run;
Solution
‎03-05-2015 10:47 AM
Super Contributor
Posts: 292

Re: Send e-mail with Hyperlink

Posted in reply to djbateman

here's an example of what I use all the time ...

filename testmsg email ' '

to =('someone@somewhere.ca')

subject=('too much fun for one day');

data _null_;

file testmsg;

put "file:\\Technology\Quality\FantasticFile.pdf";

run;

Learner
Posts: 1

Re: Send e-mail with Hyperlink

Hi Bill,

 

 

What can I do if the file link have a space?

 

for example:

 

put "file:\\program file\FantasticFile.pdf"

 

when I try it...the link is been cut when there is a space.

 

 

Frequent Contributor
Posts: 87

Re: Send e-mail with Hyperlink

Posted in reply to djbateman

Hiya, try:

filename mail email

     to=("someone@com")

     subject="Test e-mail with Hyperlink"

     content_type="text/html" ;

data _null_;

     file mail;

     put "<p>Here is a test to see if hyperlinks work in an e-mail sent from SAS:</p>" ;

     put "<p></p>";

    put '<p>URL: <a href="www.sas.com">www.sas.com</a></p>' ;

    put '<p>Directory: <a href="C:\Users\Public">C:\Users\Public</a></p>' ;

run;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 6841 views
  • 3 likes
  • 6 in conversation