DATA Step, Macro, Functions and more

Error in mail

Accepted Solution Solved
Reply
Contributor
Posts: 63
Accepted Solution

Error in mail

Hello everyone!

I want to send mail to a particular user by attaching excel file with current date from a particular location . But I am getting error while running the below program.

Can anyone help me as I am not experienced.

Location of Excel file: - 'C:\Program Files\Cisco\Meddra term updated_03JAN2013.XLS'

FILENAME Mailbox EMAIL 'manager@cisco.com'

Subject='Test Mail message'

ATTACH= 'C:\Program Files\Cisco\Meddra term updated_||put("&sysdate9"d ,date9.)||".xls"'

;

DATA _NULL_;

FILE Mailbox;

PUT "Hello";

PUT "Test mail ";

RUN;

N:B: The excel output file will be updated with current date everyday in the above location.


Accepted Solutions
Solution
‎01-02-2014 03:25 PM
Frequent Contributor
Posts: 83

Re: Error in mail

Put " rather than ' in that line of code, macros don't like running in single quotes

so subject should be

Subject="Test Mail message_&print_date"

View solution in original post


All Replies
Frequent Contributor
Posts: 83

Re: Error in mail

First question: You have set up your email setting through your .cfg file correct? My guess is yes bc it sounds like this is just a question about how to get it to go from the correct date. If not you will first need to set that up so you can email from SAS.

Second: run this line of code before the filename statement

%let print_date = %sysfunc(today(), date9.);

Third: You will need a from=("you@you.org") to=("manager@cisco.org)

Fourth: You then can run it write the attach statement as such:

ATTACH= "C:\Program Files\Cisco\Meddra term updated_&print_date..xls"

Since you previously had stated what the print_date macro should output you then can just insert it into the attach statement.

In the end the code should look like this:

%let print_date = %sysfunc(today(), date9.);

FILENAME Mailbox EMAIL from=("you@you.org")

to=("manager@cisco.org)

ATTACH= "C:\Program Files\Cisco\Meddra term updated_&print_date..xls"

;

DATA _NULL_;

FILE Mailbox;

PUT "Hello";

PUT "Test mail ";

RUN;

Contributor
Posts: 63

Re: Error in mail

Thank You very much for your great help.

One question

How to add the current date in the subject of text. Its not working. Can you please help.

Subject='Test Mail message__&print_date'

Solution
‎01-02-2014 03:25 PM
Frequent Contributor
Posts: 83

Re: Error in mail

Put " rather than ' in that line of code, macros don't like running in single quotes

so subject should be

Subject="Test Mail message_&print_date"

Contributor
Posts: 63

Re: Error in mail

Its working fine now. I forgot to ask one more question .

If I want to attach multiple file , then can I write like this.

ATTACH= ("C:\Program Files\Cisco\Meddra term updated_&print_date..xls"

                 "C:\Program Files\Cisco\Meddra term updated_&print_date..pdf"

                  "C:\Program Files\Cisco\Meddra term updated_&print_date..doc"

               )

Frequent Contributor
Posts: 83

Re: Error in mail

Correct and make sure to put the parentheses outside of the file names, they are not required if you are only sending one file, but are if you are sending multiple ones.

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 320 views
  • 3 likes
  • 2 in conversation