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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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