BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ankit1may
Calcite | Level 5
Hello all,
I am quite new to SAS and is facing challenge with respect to emails sent with SAS code.
I have to send an email "Good Day" , when there are no files to attach, and if there are any files, I have to attach the file in the email . All files needed to be attached are put in macro variable &all_files. I have defined a control variable &bha, which if 0, would mean that there are no files to attach, but if it is greater than 0, there are files to attach. The problem is , when I don't have any files to attach, the variable &all_files = '', and the code is giving error in attach statement. My coffee is below:

Filename outbox 'abc@xyz.com';

Data _null_;
If &bha =0 then do;
File outbox
From = my mail
To = xxx
Subject = 'reports';
Put 'Good Day';
End;

Else if &bha ne 0 then do;
File outbox
From = my mail
To = xxx
Subject = 'reports'
Attach= (&all_files);
Put 'attach are reports';
End;
Run;

Whenever there are no files to send, the code gives me error 'invalid value for the attach option'.

Can someone please help?
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Email from dataset is not switchable like that, you would need to wrap it in macro, something like:

%macro SendMail (bha=);

  data _null_;
    %if &bha.=0 %then %do;
      file outbox from=mymail to=xxx subject='reports';
      put 'Good Day';
    %end;
    %else %do;
      file outbox from=mymail  to=xxx subject='reports' attach=(&all_files.);
      put 'attach are reports';
    %end;
  run;

%mend SendMail;

%SendMail (bha=1);   /* For no reports, just change 1 to 0 */

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Email from dataset is not switchable like that, you would need to wrap it in macro, something like:

%macro SendMail (bha=);

  data _null_;
    %if &bha.=0 %then %do;
      file outbox from=mymail to=xxx subject='reports';
      put 'Good Day';
    %end;
    %else %do;
      file outbox from=mymail  to=xxx subject='reports' attach=(&all_files.);
      put 'attach are reports';
    %end;
  run;

%mend SendMail;

%SendMail (bha=1);   /* For no reports, just change 1 to 0 */
ankit1may
Calcite | Level 5
It really worked. Thank you:)
mark1221
Calcite | Level 5

There are various substitutions that cannot be used as a parameter expansion. You have to map the root directory as well as you have to make sure that name will not be used in the directory name. 

For more access plugins uae

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 665 views
  • 0 likes
  • 3 in conversation