Hi,
Hope all is well.
Does anybody have an email code where in if there is data an email will send with attachment and if there is no data just an email saying 'no data to report'?
Thank you in advance.
Please show your code which sends the mail when data is present.
Also describe what you mean by "no data". Dataset does not exist, or dataset has zero observations?
You can retrieve such information like this:
%let data = 0;
proc sql noprint;
select nobs into :data from dictionary.tables
where libnamem= "YOURLIB" and memname = "YOURDATASET";
/* library and dataset name must be uppercase */
quit;
You can then use &data in macro statements to run your code conditionally.
Use my previous code, then do
%if &data.
%then %do;
filename mymail email 'myemail@email.com' from='myemail@email.com'
subject='Daily Chargebacks Report'
attach=("\\shared\Auto Reports\Chargebacks Report.xlsx");
data _null_;
file mymail
to=("someone@emailcom
)
cc=("myeamil@email.com");
put 'Hi,';
put ' ';
put 'Attached is the Chargeback report.';
put ' ';
put 'Cheers';
run;
%end;
%else %do;
filename mymail email 'myemail@email.com' from='myemail@email.com'
subject='Daily Chargebacks Report'
;
data _null_;
file mymail
to=("someone@emailcom
)
cc=("myeamil@email.com");
put 'Hi,';
put ' ';
put 'No data was created!';
put ' ';
put 'Cheers';
run;
%end;
Hi @Eugenio211
Can you please clarify:
Did you want
OR
Which one?
The syntax would vary depending on your choice of language.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.