BookmarkSubscribeRSS Feed
James_79
Fluorite | Level 6

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?

 

7 REPLIES 7
James_79
Fluorite | Level 6
Yeah, I can do it easily with macro language, I was just trying to do it with Proc Lua, I just like it better. The part that I want to do conditionally is add an attachment.
Patrick
Opal | Level 21

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;

 

 

James_79
Fluorite | Level 6
I copied this and still get the "No logical assign for filename EMOUTOUT". I'm using SAS 9.04.01M4P110916, btw. I don't think that should matter here, though.
Tom
Super User Tom
Super User

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.

James_79
Fluorite | Level 6

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.

Patrick
Opal | Level 21

@James_79 

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.

SAS Innovate 2025: Register Now

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!

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
  • 7 replies
  • 1180 views
  • 0 likes
  • 4 in conversation