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;
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;
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
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.
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.
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>.
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;
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.
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
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.
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;
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.
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;
%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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.