I'm trying to send an email using the filename statement and conditionally add an attachment using PROC LUA instead of a macro procedure. However, I run into an issue when executing the filename statement for the email output inside lua.
Below is some sample code (email addresses changed) that cause this error to show up:
ERROR: No logical assign for filename EMAILOUT.
ERROR: No body file. TAGSETS.MSOFFICE2K output will not be created.
proc lua; submit; sas.submit([[ filename emailOut email to="someone@somewhere.com" from=("sender@somewhere.com") subject = "test email" content_type="text/html" type="text/html" ; ods Tagsets.Msoffice2k file=emailout style=HTMLBlue OPTIONS (PAGEBREAK="NO"); proc odstext; p "This is a test"; run; ods Tagsets.Msoffice2k close; ]]) endsubmit; run;
I cannot seem to figure out how to get this to work while INSIDEproc lua. I can set up the emailOut fileref before proc lua and that will work, but then I can't conditionally add an attachment...or can it? Thoughts?
If your goal is just to make the email dynamic, use macro language. Which part of the process needs to be done conditionally?
I don't have tagset Msoffice2k installed so used excelxp instead. Below code works for me - but writes of course the xml to the email body.
proc lua;
submit;
sas.submit([[
filename emailOut email
to="someone@somewhere.com"
from=("someone@somewhere.com")
subject = "test email"
content_type="text/html" type="text/html"
;
ods tagsets.excelxp
file=emailout
style=HTMLBlue
;
proc odstext;
p "This is a test";
run;
ods tagsets.excelxp close;
]])
endsubmit;
run;
That seems strange. Are you sure there is not some minor difference between the filename statement generated by LUA and what you tested in regular code?
Is it possible that the way MSOFFICE2K destination creates its files works differently from the other destination that you got to work? For example I think the HTML destination works differently than destinations like XLSX.
It might be that you need to create the file first and then attach it to the email instead of trying to attach via the EMAIL filename engine.
Tom:
Is what you asked possible? Probably, but even so I ran the exact same code that Patrick tested, just supplied valid email addresses, and still received the errors. Creating the file first doesn't matter when I didn't even try to attach the file yet.
I've given up on this. Since I can just create a macro to do it, that's what I'll do.
All: Thanks for trying to help. I know it was an obscure problem.
I've done my trial on a laptop with a local SAS installed. When I've executed the code then my antivirus software prompted me that an application is trying to send an email.
So just as an idea: May be when using Lua some antivirus software in your environment blocks the the file - but when using SAS directly then things get through.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.