The SAS Output Delivery System and reporting techniques

How to send SAS email to multiple people

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 82
Accepted Solution

How to send SAS email to multiple people

I am using below code to send an email:

data _null_;

file sendit email

from="Support@yahoo.com"

to=("xxx@yahoo.com" )

cc=("yyy@yahoo.com")

subject="Report 123"

importance="High"

attach="/home/report.zip";

put "Regards,";
put "Support Team";
put;

My problem is that the To: field needs to read email addresses from a list (dataset). Now I can loop through a dataset ,pick out each email address and send a separate email to each person.

But what i want is to send a single email with all those names in the To field.

How can I do this?


Accepted Solutions
Solution
‎05-06-2014 11:20 AM
Esteemed Advisor
Esteemed Advisor
Posts: 7,203

Re: How to send SAS email to multiple people

Hi,

Two steps.  Create your list of emails, then set that in a data _null_ and call execute using that loop:

proc sql;
  create table LOOP as
  select  distinct EMAIL
  from    WORK.HAVE;
quit;

data _null_;
  set loop end=last;
  if _n_=1 then do;
    call execute('data _null_;
                    file sendit email
                    from="Support@yahoo.com" to=("'||strip(email)||'"');
  end;
  else do;
    call execute(',"'||strip(email)||'"');
  end;
  if last then do;
    call execute(') cc=("yyy@yahoo.com") subject="Report 123"...

  end;
run;


View solution in original post


All Replies
Solution
‎05-06-2014 11:20 AM
Esteemed Advisor
Esteemed Advisor
Posts: 7,203

Re: How to send SAS email to multiple people

Hi,

Two steps.  Create your list of emails, then set that in a data _null_ and call execute using that loop:

proc sql;
  create table LOOP as
  select  distinct EMAIL
  from    WORK.HAVE;
quit;

data _null_;
  set loop end=last;
  if _n_=1 then do;
    call execute('data _null_;
                    file sendit email
                    from="Support@yahoo.com" to=("'||strip(email)||'"');
  end;
  else do;
    call execute(',"'||strip(email)||'"');
  end;
  if last then do;
    call execute(') cc=("yyy@yahoo.com") subject="Report 123"...

  end;
run;


Frequent Contributor
Posts: 82

Re: How to send SAS email to multiple people

Thanks. Can  you tell me what is the purpose of this symbol?

||

In sql, we use this to concatenate strings, what is the purpose in this context?

Trusted Advisor
Posts: 1,213

Re: How to send SAS email to multiple people

It's the same concatenation operator as you would expect.

For example, you have a string literal 'data _null_; file sendit... ', concatenated to the value of the EMAIL dataset variable, concatenated to another string literal "'" (a single quote mark).

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 1189 views
  • 6 likes
  • 3 in conversation