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.
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"
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;
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'
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"
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"
)
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.