BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
djbateman
Lapis Lazuli | Level 10

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Bill
Quartz | Level 8

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

12 REPLIES 12
Cynthia_sas
SAS Super FREQ

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

djbateman
Lapis Lazuli | Level 10

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.

Quentin
Super User

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.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
Quentin
Super User

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>.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
djbateman
Lapis Lazuli | Level 10

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;

Quentin
Super User

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.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
Cynthia_sas
SAS Super FREQ

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

Quentin
Super User

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;
The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
Bill
Quartz | Level 8

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;

LUISGARCIA27
Calcite | Level 5

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.

 

 

SteveNZ
Obsidian | Level 7

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;

HRI1
Calcite | Level 5

%LET email =test@gmail.com ;
%LET url = https://communities.sas.com ;

filename mail email
to=("&email")
subject="Test e-mail with Hyperlink"
data _null_;
file mail;
put "&url";
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 12 replies
  • 48349 views
  • 3 likes
  • 7 in conversation