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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.