Hi.
I have files that should be send out every week. These files changes names e.g. "filename_1" next week it will be "filename_2".
But it only takes the filename that I manually wrote which is filename_1. Is there a way to say that it should take the latest file with this name everyweek,instead of me doing it manually every week?
This is my code for the email (I manually wrote the filename):
filename outbox email
from="test@test.dk"
to="test@test.dk"
type='text/html'
subject='test'
attach=("F:\filename_1.png" ct='png')
ods html body=outbox rs=none style=Htmlblue;run;
ods html close;
Use a macro variable to designate the attachment file when you create it.
For example:
/* Create the attachment file in the WORK library so it will be automatically deleted when the SAS session ends */
%let myFile=%sysfunc(pathname(work))\Report.pdf;
ods pdf body="&myFile" style=Journal;
PROC SQL;
title "Details from sashelp.class where age > 10";
SELECT * from sashelp.class where age > 10;
quit;
ods pdf close;
/* Set up this email using the PDF created above as an attachment*/
filename mymail email "my.recipient@example.com"
subject="Report for sashelp.class"
lrecl=256 type="TEXT/HTML"
/* Attachment information */
attach="&myFile";
ods html5 body=mymail style=sasweb;
options nocenter;
title;
/* Write the body of the email */
data _null_;
file print;
put "Here is the information you asked for.";
put "May the SAS be with you!";
put "Mark";
run;
ods html5 close;
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.